Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run elastic search as root user

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?

like image 947
Santosh Hegde Avatar asked Nov 23 '16 13:11

Santosh Hegde


People also ask

How do I run elastic search as root?

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.

What user does Elasticsearch run as?

linux - Running ElasticSearch as the root user - Stack Overflow.

Is it possible to run Elasticsearch as root?

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.

How do I prevent Elasticsearch from reading user data?

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.

How do I start Elasticsearch from the command line?

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.

How do I add and remove users in Elasticsearch?

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.


2 Answers

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.

like image 34
Rajeev Rathor Avatar answered Sep 29 '22 19:09

Rajeev Rathor


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

like image 90
Devasish Avatar answered Sep 29 '22 21:09

Devasish