25

I am trying to run Elasticsearch 2.1.1 in my Linux machine which I am the root user of it.

When I tried to execute the Elasticsearch.I am getting the following error:

Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.

I referred some suggestion available in internet, they mentioned to run it as different user. My scenario is to run as root user only. How to overcome this problem without running as different user.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Mangoski
  • 2,058
  • 5
  • 25
  • 43
  • I do not believe there is a way around it, you have to run it as another user for security reasons. – IanGabes Jan 21 '16 at 18:37
  • It is extremely dangerous to run a webserver as root. This must not happen. Especially this answer nails it: http://askubuntu.com/a/16201/35185 Please refer to this thread: http://askubuntu.com/questions/16178/why-is-it-bad-to-login-as-root – Semo Jan 13 '17 at 07:42

6 Answers6

48

Based of the following code-snippet looks like you should be able to achieve this by enabling property es.insecure.allow.root

Example :

bin/elasticsearch -Des.insecure.allow.root=true
keety
  • 17,231
  • 4
  • 51
  • 56
  • Thank yo so much . Your suggestion did the trick but now I am facing different error. I am pasting the error below, `Exception in thread "main" java.lang.IllegalStateException: Failed to obtain node lock, is the following location writable?: [/anvs/indexstore/mysample] Likely root cause: java.io.IOException: No locks available at sun.nio.ch.FileDispatcherImpl.lock0(Native Method) at sun.nio.ch.FileDispatcherImpl.lock(FileDispatcherImpl.java:90) at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1082)` – Mangoski Jan 22 '16 at 08:29
  • did you check the permissions of folder /anvs/indexstore/mysample ? – keety Jan 22 '16 at 18:49
  • 9
    The current answer no longer works in the latest elasticsearch. – rjurney Jan 05 '17 at 03:07
  • 2
    @rjurney. Yes the above option is not working in version 5.X and above. Is there any way to overcome this? – Mangoski Mar 15 '17 at 10:27
  • Hi did you find the answer for ES5? – Tomer Apr 23 '17 at 07:50
  • @Tomer. You have to create a non-root user in version 5.X – Mangoski May 30 '17 at 17:59
10
  1. Open script file:

    vi bin/elasticsearch

  2. Add property for allow root:

    ES_JAVA_OPTS="-Des.insecure.allow.root=true"

  3. Save and close.
  4. You can start by root now.

Good luck.

Viet Tran
  • 1,173
  • 11
  • 16
4

You can also create alias

alias elasticsearch='elasticsearch -Des.insecure.allow.root=true'

Add above line in bashrc file, After that elasticsearch command will work.

Ravi Prajapati
  • 2,536
  • 1
  • 11
  • 9
  • @BoPennings Yes it was deprecated in 5.X version.. You have to create a non-root user in you box and you ahve to change the elasticsearch username and group to newly created non-root user and then you have to start the process. – Mangoski May 30 '17 at 17:58
1

You should change the owner and group of the elasticsearch-X.X.X and run as that user. It works in elasticsearch-5.3.0

Hunter
  • 21
  • 3
1

There are two workarounds to resolve this issue :

Solution 1: download zip file n unzip then start by following command

bin/elasticsearch -Des.insecure.allow.root=true -d

Solution 2:

vi bin/elasticsearch

Add property to allow root to run two instance:

ES_JAVA_OPTS="-Des.insecure.allow.root=true"

Save and close. You can start by root now.

truekiller
  • 470
  • 6
  • 19
0

we need to create a new user in Linux server say user = es and grant sudo chown -R es elasticsearch-6.1.0/ then you can switch 'es' user account and run ./elasticsearch-6.1.0/bin/elasticsearch

mahi
  • 1
  • 1