https://blog.csdn.net/lahand/article/details/78954112
如果以root身份运行将会出现以下问题,这个错误,是因为使用root用户启动elasticsearch,elasticsearch是不允许使用root用户启动的
[root@iZbp1epx1ncetamddfjnxwZ bin]# ./elasticsearch
[2018-01-02T17:42:42,296][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:125) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.1.1.jar:6.1.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.1.1.jar:6.1.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:322) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.1.1.jar:6.1.1]
... 6 more
ES5之后[解决方法1],[解决办法2],已经不能用了,请使用[解决办法3],[解决办法4]
解决方法1:
在执行elasticSearch时加上参数-Des.insecure.allow.root=true,完整命令如下
- ./elasticsearch -Des.insecure.allow.root=true
解决办法2:
用vim打开elasicsearch执行文件,在变量ES_JAVA_OPTS使用前添加以下命令
- ES_JAVA_OPTS="-Des.insecure.allow.root=true"
如下图所示,这个方法的好处是以后不用添加参数就能以root身份执行了
解决办法3:
我们需要添加用户。
adduser *** //添加用户
passwd *** //给用户赋值
添加完用户之后:
用root用户执行 : chown -R 文件夹名 用户名
将这几个压缩包所在的文件夹及解压完的文件夹权限给你新建的用户。之后再使用新用户启动就OK了。
参考:https://www.cnblogs.com/yidiandhappy/p/7737003.html,http://blog.csdn.net/u010317005/article/details/52205825
解决办法4:
如果是用root账号启动,会报以下错误
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.
这是出于系统安全考虑设置的条件。由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑,
建议创建一个单独的用户用来运行ElasticSearch创建elsearch用户组及elsearch用户
groupadd elsearch useradd elsearch -g elsearch -p elasticsearch更改elasticsearch文件夹及内部文件的所属用户及组为elsearch:elsearch
cd /opt chown -R elsearch:elsearch elasticsearch切换到elsearch用户再启动
su elsearch cd elasticsearch/bin ./elasticsearch启动后打印信息如下
[ [ [ [ [ [ [ [ [ [ [
ElasticSearch后端启动命令
./elasticsearch -d