I'm getting the error below when I try to start ElasticSearch 5.0 with ./elasticsearch
:
[2016-11-23T13:44:09,507][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:116) ~[elasticsearch-5.0.1.jar:5.0.1] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:103) ~[elasticsearch-5.0.1.jar:5.0.1] at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.0.1.jar:5.0.1] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96) ~[elasticsearch-5.0.1.jar:5.0.1] at org.elasticsearch.cli.Command.main(Command.java:62) ~[elasticsearch-5.0.1.jar:5.0.1] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) ~[elasticsearch-5.0.1.jar:5.0.1] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:73) ~[elasticsearch-5.0.1.jar:5.0.1] Caused by: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:96) ~[elasticsearch-5.0.1.jar:5.0.1] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:155) ~[elasticsearch-5.0.1.jar:5.0.1] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286) ~[elasticsearch-5.0.1.jar:5.0.1] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:112) ~[elasticsearch-5.0.1.jar:5.0.1] ... 6 more
I switched to another user and tried sudo ./elasticsearch
and got the same error.
How do I start ElasticSearch as the root user?
Step 1: Pull images of elastic search from Docker/install from web. Step 2: Execute Docker-Exec command to get location on Bash. Step 3: vi bin/elasticsearch.
linux - Running ElasticSearch as the root user - Stack Overflow.
1. java.lang.RuntimeException: can not run elasticsearch as root. Elasticsearch is a process, which I believe has not need to access any system root features and can run easily without any of the the root privilege. If you are running Elasticsearch on container, then only Container root process should run as a root like Docker and Kubernetes.
To ensure that Elasticsearch can read the user and role information at startup, run elasticsearch-users useradd as the same user you use to run Elasticsearch. Running the command as root or some other user updates the permissions for the users and users_roles files and prevents Elasticsearch from accessing them.
Elasticsearch can be started from the command line as follows: ./bin/elasticsearch. By default, Elasticsearch runs in the foreground, prints its logs to the standard output (stdout), and can be stopped by pressing Ctrl-C.
If you use file-based user authentication, the elasticsearch-users command enables you to add and remove users, assign user roles, and manage passwords. If you use the built-in file internal realm, users are defined in local files on each node in the cluster.
Root cause of this issue is: ElasticSearch is not allowed to run from root owner. There is another possiblity for this issue "Java path is set for root user only not for all other users". Solution of this issue:
Step 1: Change the ownership of elasticSearch directory from root to other user by command. $sudo chown -R current_User:Group_Name elasticsearch-5.5.0
Setp 2: Check Java set in classpath for current user[not only for root]. If command : $java -version or echo $JAVA_HOME command giving empty result. That means we should set Java in classpath [system env varible] for current user then Follow Step 3. otherwise start elasticsearch service.
Step 3: Edit /etc/profile and add two lines as per your system dir export JAVA_HOME="Java dir location"
export PATH=$JAVA_HOME/bin:$PATH Run $source source /etc/profile
After this run elasticSearch service. It worked for me perfectly.
Elasticsearch can't be run an root user. Elasticsearch itself restricts this. A new user named elasticsearch and group named elasticsearch is automatically created when we install elasticsearch. Can check entries by using following commands
$ sudo less /etc/passwd | grep "elasticsearch" $ sudo less /etc/group | grep "elasticsearch"
We need to change ownership of all elasticsearch related files. Please follow the steps mentioned below.
Steps:
1.Change owership of all ES related files from root to elasticsearch using example cmd below.
$ sudo chown elasticsearch:elasticsearch -R /usr/share/elasticsearch $ sudo chown elasticsearch:elasticsearch -R /var/log/elasticsearch $ sudo chown elasticsearch:elasticsearch -R /var/lib/elasticsearch $ sudo chown elasticsearch:elasticsearch -R /etc/default/elasticsearch $ sudo chown elasticsearch:elasticsearch -R /etc/elasticsearch
2.Open /etc/default/elasticsearch
file and do the following things
a)JAVA_HOME=your/java/home/path b)add the following entries at the end i) START_DAEMON=true ii) ES_USER=elasticsearch iii) ES_GROUP=elasticsearch
3.Now enable elasticsearch service and start
$ sudo systemctl enable elasticsearch $ sudo systemctl start elasticsearch $ sudo systemctl status elasticsearch
4.Test elasticsearch by using curl. Say your host ip is 192.168.5.194 and ES running on port 9200
$ curl -X GET ‘192.168.5.194:9200’
DONE!!
Ref. : https://stackoverflow.com/a/48390311/1445978
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With