elasticsearch can't start with an non-root user - elasticsearch

I am using elasticsearch as a search engine for my website.After I downloaded the elasticsearch I use the command ./bin/elasticsearch
I got an error
org.elasticsearch.bootstrap.StartupException:
java.lang.RuntimeException: can not run elasticsearch as root
I google it and run the command
groupadd esgroup
useradd esuser -g esgroup -p espassword
chown -R esuser:esgroup elasticsearch
and I switch to esuser but I cant cd /root
bash: cd: /root: Permission denied
so I have to switch to root user and stay at /root/elasticsearch/ and change to esuser
then I run the command
./bin/elasticsearch
this time I get a different error
Error: Could not find or load main classorg.elasticsearch.bootstrap.Elasticsearch
I already install java-1.8.0-openjdk-devel and the java -version javac command works
I am using centos6 x64
Is there something I miss?

please download & install the whole elasticsearch zip as a non-root user instead of trying to fiddle with permissions inside of the /root/ directory (where also data & logs are written to).
if you dont want to deal with such things, the easiest way might be to use one of the existing packages.

Related

How to run nvm command from bash file in GCP Cloud Shell (global install)?

What we're trying to do
We are using Cloud Shell Editor (IDE) on GCP.
According to the documentation for Environment customization script:
Cloud Shell automatically runs the script,
$HOME/.customize_environment, when your instance boots up. Unlike
.profile or .bashrc, this script runs once when Cloud Shell boots
(rather than once for each shell login).
This script runs as root and you can install any packages that you
want to exist in each Cloud Shell session using Debian package
management commands.
For example, if you'd like to have erlang installed on Cloud Shell,
your .customize_environment file will look like this:
#!/bin/sh
apt-get update
apt-get -y install erlang
We are trying to pre-install node versions and automate configuration for our developers using nvm.
Where we have issues
We've looked into several articles on making nvm callable from within a bash script file (the .customize_environment file):
nvm command not available in bash script
Can't use nvm from bash script
Node Version Manager install - nvm command not found
None of these answers seem to resolve our issue.
GCP nvm details
Cloud Shell pre-installs nvm (globally); it is located at /usr/local/nvm/nvm.sh.
There is no ~/.nvm folder.
I can run nvm without issue from Cloud Shell (command line) directly.
I cannot run nvm (nor using the for path) from a bash file.
Closest attempt
Running the following comes close, but I'm limited on privileges that you can't sudo around due to Cloud Shell limitations:
. /usr/local/nvm/nvm.sh
nvm install 14
Results in:
Downloading and installing node v14.15.4...
mkdir: cannot create directory ‘/usr/local/nvm/.cache/bin/node-v14.15.4-linux-x64’: Permission denied
creating directory /usr/local/nvm/.cache/bin/node-v14.15.4-linux-x64/files failed
Downloading https://nodejs.org/dist/v14.15.4/node-v14.15.4-linux-x64.tar.xz...
Warning: Failed to create the file
Warning: /usr/local/nvm/.cache/bin/node-v14.15.4-linux-x64/node-v14.15.4-linux-
Warning: x64.tar.xz: No such file or directory
curl: (23) Failed writing body (0 != 966)
Binary download from https://nodejs.org/dist/v14.15.4/node-v14.15.4-linux-x64.tar.xz failed, trying source.
grep: /usr/local/nvm/.cache/bin/node-v14.15.4-linux-x64/node-v14.15.4-linux-x64.tar.xz: No such file or directory
Provided file to checksum does not exist.
Binary download failed, trying source.
Detected that you have 4 CPU core(s)
Running with 3 threads to speed up the build
mkdir: cannot create directory ‘/usr/local/nvm/.cache/src’: Permission denied
creating directory /usr/local/nvm/.cache/src/node-v14.15.4/files failed
Downloading https://nodejs.org/dist/v14.15.4/node-v14.15.4.tar.xz...
Warning: Failed to create the file
Warning: /usr/local/nvm/.cache/src/node-v14.15.4/node-v14.15.4.tar.xz: No such
Warning: file or directory
curl: (23) Failed writing body (0 != 965)
Binary download from https://nodejs.org/dist/v14.15.4/node-v14.15.4.tar.xz failed, trying source.
grep: /usr/local/nvm/.cache/src/node-v14.15.4/node-v14.15.4.tar.xz: No such file or directory
Provided file to checksum does not exist.
Important lines: mkdir: cannot create directory ‘...’: Permission denied
I can't sudo around it, run usermod (e.g. usermod -a -G staff $(whoami)), even though Google's documentation says I should be able to:
When you set up a Cloud Shell session, you get a regular Unix user account with a username based on your email address. With this access, you have full root privileges on your allocated VM and can even run sudo commands, if you need to.
Question
How can we use nvm within a bash script file in GCP's Cloud Shell?
I managed to resolve this with the help of comments by #Kolban and #HarshManvar.
I assume this solution would also work for any other scripts that aren't working with direct calls from .customize_environment.
The example below is influenced by the answer found here. The code installs a specific node version.
Note: nvm is globally installed in Cloud Shell by default.
#!/usr/bin/bash
sudo su -c '. /usr/local/nvm/nvm.sh && nvm install 14'

Running gsutil on instance using python subprocess - access permissions?

I have a python script that does calculations on google compute engine instances. The code works fine in terms of doing the calculations, but at certain points in the code it needs to add/delete files from a cloud storage bucket and I do this using gsutil. This works well when run from my local computer, but isn't working when the same code is run from a google cloud instance. By "not working" an error message is reported at the offending line, but my code carries on running and just ignores the steps that involve gsutil.
My understanding from Google's documentation is that gcloud instances boot with the "gsutil" utility already installed. My instances boot running a script like this (where is my actual google username):
#! /bin/bash
sudo apt-get update
sudo apt-get -yq install python-pip
sudo pip install --upgrade google-cloud
sudo pip install --upgrade google-cloud-storage
sudo pip install --upgrade google-api-python-client
sudo pip install --upgrade google-auth-httplib2
mkdir -p /home/<xxxx>/code
mkdir -p /home/<xxxx>/rawdata
mkdir -p /home/<xxxx>/processeddata
sudo chown -R <xxxx> /home/<xxxx>
gsutil cp gs://<codestorebucket>/worker-python-code/* /home/<xxxx>/code/
gsutil -m cp gs://<rawdatabucket>/* /home/<xxxx>/rawdata/
I dont run my code from the boot script yet as I want to "SSH" into the instance and run it myself from the command line while I am still developing. When I SHH into the instance the directories have all been created and all of the code and raw datafiles have been copied. I can run my ".py" file and it runs, but there are lines which use the python command:
subprocess.call('gsutil -q rm gs://<mybuckname>/<myfilename>', shell=True)
This generates an error which reads:
ERROR: (gsutil) Failed to create the default configuration. Ensure your have the correct permissions on: [/home/<xxxx>/.config/gc
loud/configurations].
Could not create directory [/home/<xxxx>/.config/gcloud/configurations]: Permission denied.
If it provides any clues, in the "daemon.log" file there an error line which reads:
chown: invalid user: ‘<xxxxx>’
which is reported when the sudo chown... command line runs.
The instances have full access to all APIs. If I run
whoami
The response is "xxxxx". If I run
echo $UID
The response is 1000.
I am a Linux novice, as I have only "learnt" about it through needing to do stuff on google instances. There is a link here where a user appears to have a similar problem. He fixes it using a sudo chown type command line, but when I run an equivalent command I am told that it "cannot access '/home/paulgarlick07/.config/': No such file or directory"
I'm really confused, and any help would be very much appreciated. If any additional info is required to help resolve this please let me know!
gsutil is not a program. It is a script. Therefore you need to execute a shell with gsutil as a command line argument. You will need to pass the full pathname for gsutil which might be different on your system.
subprocess.call('/bin/sh /usr/bin/gsutil -q rm gs://<mybuckname>/<myfilename>', shell=True)
If you are running gsutil from a service, then you will need to ensure that the user that the service is running under has gsutil setup. gsutil stores its configuration files based from the home directory of the user that it is executing under.

Elasticsearch won't start on centos, permission denied

I installed elasticsearch this way :
retrieved the tar.gz on windows, extracted it and put it on a zip
uploaded the zip over ssh on a server and use 'unzip file' to unzip it.
I modified the elasticsearch file so that it has this line
export JAVA_HOME = "/home/xxx/project1/jdk1.8.0_73_linux64"
just below
#!/bin/sh
now when I go into /home/xxx/project1/elasticsearch/bin and type
./elasticsearch
I get
-bash: ./elasticsearch: Permission denied
What could I do to get more information about the problem?
I'm logged as user xxx
Thanks.
The problem is, that you've installed elastic being logged in as root. Now you're surely logged in as not root. If you're working as a user with root privileges, you potentially could start elastic, but it tells you, you can't run in as root. The owner of your elastic folder is root (he installed it). So, all you need to do is to change the owner of a folder to your xxx-user (to let him run elastic). You can easily do it executing a command:
chown -R new_owner path
for example, user is xxx and path is /opt/elasticsearch-2.3.5:
chown -R xxx /opt/elasticsearch-2.3.5
"-R" parameter ensures, that not only folder, but all files inside will recursively change the owner you provide.
Try to install using the package Yum Install for elasticsearch.
Else try: Its sounds like the user permission to access the files.
Ensure that you have downloaded the linux distribution (Optional) Since you have mentioned its tar.gz.
If you have extracted using sudo command then you need to change the user permission for elasticsearch folder to logged in user OR start the elasticsearch using sudo command
sudo ./elasticsearch -d
Check the execution permission if not please do the same by following command
sudo chmod +x /home/xxx/project1/elasticsearch/bin/elasticsearch.sh
Try this things if not please create a chat window and invite me.
Looking ahead I will immediately say that the ES app doesn't work using the sudo
In my case with ES 6.8.1 version on ubuntu i solved the problem using this steps:
Add the current user(or any other) to ES group:
sudo adduser <yourName> elasticsearch
Add possibility to execute ES:
sudo chmod +x /usr/share/elasticsearch/bin/elasticsearch
Then i changed owner of some paths**, in my case these were:
sudo chown -R <yourName>:elasticsearch /etc/default/elasticsearch
sudo chown -R <yourName>:elasticsearch /etc/elasticsearch
sudo chown -R <yourName>:elasticsearch /var/log/elasticsearch
**I started the application several times and then looked where I had no permission
Then i started ./usr/share/elasticsearch/bin/elasticsearch and saw the long-awaited JSON on port 9200 :)
Hope this will help someone.

Run HDFS as sudo user

Due to a script I am using to install Hadoop, I am having to run all commands as sudo. I am trying to start HDFS by typing "start-dfs.sh", but it says
sudo: start-dfs.sh: command not found
I typed the full path name i.e. sudo /home/ubuntu/hadoop-2.2.0/sbin/start-dfs.sh, but that did not work either. Does anyone know how I can start the HDFS service as sudo? Thanks in advance!

connect failed mongo db on mac osx

i'm trying to learn mongo db on my mac. I installed mondgo db using homebrew and it appeard successful. I created the dir /data/db. when I type mongo into the terminal I get:
Error: couldn't connect to server [a bunch of numbers] at src/mongo/shell/mongo.js:145 exception:connect failed
I looked at the following answer on SO: Installing and Running MongoDB on OSX
in the check answer it says:
1) Start a terminal for your mongo server
2)Go to mongo/bin directory
What does it mean to start a terminal for your server? does that mean just open up a new terminal window?
Where can I find the mongo/bin directory?
Any other suggestions on getting mondoDB up and running would be appreciated.
you should read the documentation here: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
And follow the instructions.
In this case the [bunch of numbers] are the hostname/ip and port number that the binary mongo has tried to connect to. What it's telling you is that there is no mongod binary listening on the hostname and port that mongo is trying to connect to.
You will need to start mongod before you are able to connect to it with a mongo shell. The documentation above outlines this further.
If you use homebrew the mongodb binaries will automatically be put on your path which means you won't need to cd into another directory like mongo/bin.
Good luck.
Probably you run the mongodb first time. Based on the documentation you must follow a few steps and then you are ready to go.
First, create main db directory:
sudo mkdir -p /data/db
Make sure that you have a read and write permission on that directory:
sudo chown `id -u` /data/db
And to listen to default port, run:
mongod
Finally keep in mind that after the run "mongod" command do not close console tab. Open a new tab (Cmd + T) and run other commands on the new window. To close the mongod session simply hit the Ctrl + C on the previous tab.
when everything mentioned above did not work. I did the following thing (in Mac)
cd ~
mkdir -p data/db
After creating directory in home(which will be definitely allowed) most imp command is below
mongod --dbpath ~/data/db &
So that it could take the path of db which was in home directory (as we are not able to create in / dir.
To avoid it running frequently, put the above command in .bash_profile file in home directory so that it will automatically run the above command whenever we try to use terminal in Mac
Note: Whenever we open the terminal it will execute the above command so that we can access the mongodb (I understand this should be taken place in background but it works fine)
We need to press enter/return key to get the regular command line terminal and continue doing our work
These steps worked for me well on Mac, you can give a shot, make sure you install brew first and put these lines in terminal line by line:
brew update
brew install mongodb
brew install mongodb --with-openssl
brew install mongodb --devel
sudo mkdir -p /data/db
sudo chown -R [your username] /data/db
(Replace with your username with what you can get by typing whoami in the terminal)
mongod
Run you app, for example localhost:8000

Resources