Are you getting below exception while running ElasticSearch?
java.lang.RuntimeException: can not run elasticsearch as root
Why is it ElasticSearch is not allowed to run 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.
Here is a complete exception:
root@localhost:/user/crunchify/elasticsearch-6.7.0/bin# ./elasticsearch OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. OpenJDK 64-Bit Server VM warning: UseAVX=2 is not supported on this CPU, setting it to UseAVX=1 [2019-03-30T18:44:11,186][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] 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:163) ~[elasticsearch-6.7.0.jar:6.7.0] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.7.0.jar:6.7.0] at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.7.0.jar:6.7.0] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.7.0.jar:6.7.0] at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.7.0.jar:6.7.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.7.0.jar:6.7.0] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.7.0.jar:6.7.0] Caused by: java.lang.RuntimeException: can not run elasticsearch as root at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.7.0.jar:6.7.0] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.7.0.jar:6.7.0] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.7.0.jar:6.7.0] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.7.0.jar:6.7.0] ... 6 more
How to fix this issue?
- Add local user using command
adduser
. - Add user to
sudoers file
using commandusermod
.
root@localhost:/# adduser crunchify Adding user `crunchify' ... Adding new group `crunchify' (1001) ... Adding new user `crunchify' (1001) with group `crunchify' ... The home directory `/home/crunchify' already exists. Not copying from `/etc/skel'. Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for crunchify Enter the new value, or press ENTER for the default Full Name []: Crunchify Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] Y root@localhost:/# usermod -aG sudo crunchify
Now login as a newly created user:
root@localhost:/# sudo su crunchify crunchify@localhost:/$
Try running Elasticsearch again and you should be all good.
Here is a complete tutorial on how to setup Elasticsearch.
How to Install and Configure Elasticsearch on your Dev/Production environment?