elasticsearch启动报错:can not run elasticsearch as root

Posted 爵士灬

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了elasticsearch启动报错:can not run elasticsearch as root相关的知识,希望对你有一定的参考价值。

java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:111)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:178)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
For complete error details, refer to the log at /opt/ES/elasticsearch-7.10.2/logs/elasticsearch.log
[root@localhost bin]# 2023-04-25 17:46:54,138823 UTC [5722] INFO Main.cc@103 Parent process died - ML controller exiting

原因是elasticsearch为了安全,不允许使用root用户启动,由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考虑,需要创建一个单独的用户用来运行ElasticSearch。

 

下面是具体步骤:

创建用户组和用户

 

groupadd elsearch
useradd elsearch -g elsearch -p codingwhy

更改 elasticsearch-6.5.2 文件夹及内部文件的所属用户及组为elsearch

 chown -R elsearch:elsearch elasticsearch-7.10.2

 

切换用户并启动 elasticsearch

su elsearch
./elasticsearch

通过以上方法,就能正常启动elasticsearch了。

 

elasticsearch: can not run elasticsearch as root

进入bin目录启动elasticsearch:

lunadeMacBook-Air:elasticsearch-6.1.0 luna$ cd bin/
lunadeMacBook-Air:bin luna$ sudo ./elasticsearch
Password:
[2018-02-04T17:15:48,785][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.0.jar:6.1.0]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.1.0.jar:6.1.0]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.1.0.jar:6.1.0]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.1.0.jar:6.1.0]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.1.0.jar:6.1.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.1.0.jar:6.1.0]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.1.0.jar:6.1.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.1.0.jar:6.1.0]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.1.0.jar:6.1.0]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:322) ~[elasticsearch-6.1.0.jar:6.1.0]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.1.0.jar:6.1.0]
    ... 6 more

 

由于elasticsearch权限控制严格,不能用root用户启动。

那就把elasticsearch这个文件夹授权个一个用户吧。

1、进入安装目录:

lunadeMacBook-Air:local luna$ cd 
lunadeMacBook-Air:~ luna$ cd /usr/local/
lunadeMacBook-Air:local luna$ ll
total 0
drwxr-xr-x  11 root  wheel  374  2  3 21:31 ./
drwxr[email protected] 10 root  wheel  340  5 23  2017 ../
drwxr-xr-x   3 root  wheel  102  8 29 14:01 CNCB/
drwxr-xr-x   5 root  wheel  170  6 17  2016 bin/
drwxr[email protected] 12 luna  wheel  408  2  4 17:27 elasticsearch-6.1.0/
drwx------   8 luna  wheel  272  2  3 21:08 lib/
drwxr-xr-x   3 root  wheel  102  8 29 14:01 libexec/
drwxr-xr-x   2 root  wheel   68  6 18  2017 mysql/
drwxr-xr-x   3 root  wheel  102 11 14 00:41 redis/
drwxr-xr-x   3 root  wheel  102  3  7  2017 remotedesktop/
drwxr-xr-x   6 luna  wheel  204  2  3 21:08 tools/

2、授权 elasticsearch-6.1.0给我笔记本登陆用户luna

lunadeMacBook-Air:local luna$ sudo chown -R luna elasticsearch-6.1.0/

3 、启动

lunadeMacBook-Air:bin luna$ ./elasticsearch
[2018-02-04T17:27:51,275][INFO ][o.e.n.Node               ] [] initializing ...
[2018-02-04T17:27:51,679][INFO ][o.e.e.NodeEnvironment    ] [HcAbRrt] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [31.8gb], net total_space [111.8gb], types [hfs]
[2018-02-04T17:27:51,680][INFO ][o.e.e.NodeEnvironment    ] [HcAbRrt] heap size [990.7mb], compressed ordinary object pointers [true]
[2018-02-04T17:27:51,684][INFO ][o.e.n.Node               ] node name [HcAbRrt] derived from node ID [HcAbRrt4RVqvazgkI-W18Q]; set [node.name] to override
[2018-02-04T17:27:51,684][INFO ][o.e.n.Node               ] version[6.1.0], pid[39966], build[c0c1ba0/2017-12-12T12:32:54.550Z], OS[Mac OS X/10.12.6/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_91/25.91-b14]
[2018-02-04T17:27:51,685][INFO ][o.e.n.Node               ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/usr/local/elasticsearch-6.1.0, -Des.path.conf=/usr/local/elasticsearch-6.1.0/config]
[2018-02-04T17:27:54,536][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [aggs-matrix-stats]
[2018-02-04T17:27:54,536][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [analysis-common]
[2018-02-04T17:27:54,537][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [ingest-common]
[2018-02-04T17:27:54,537][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [lang-expression]
[2018-02-04T17:27:54,537][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [lang-mustache]
[2018-02-04T17:27:54,538][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [lang-painless]
[2018-02-04T17:27:54,538][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [mapper-extras]
[2018-02-04T17:27:54,539][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [parent-join]
[2018-02-04T17:27:54,539][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [percolator]
[2018-02-04T17:27:54,539][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [reindex]
[2018-02-04T17:27:54,539][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [repository-url]
[2018-02-04T17:27:54,539][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [transport-netty4]
[2018-02-04T17:27:54,539][INFO ][o.e.p.PluginsService     ] [HcAbRrt] loaded module [tribe]
[2018-02-04T17:27:54,540][INFO ][o.e.p.PluginsService     ] [HcAbRrt] no plugins loaded
[2018-02-04T17:27:59,914][INFO ][o.e.d.DiscoveryModule    ] [HcAbRrt] using discovery type [zen]
[2018-02-04T17:28:01,155][INFO ][o.e.n.Node               ] initialized
[2018-02-04T17:28:01,155][INFO ][o.e.n.Node               ] [HcAbRrt] starting ...
[2018-02-04T17:28:02,013][INFO ][o.e.t.TransportService   ] [HcAbRrt] publish_address {127.0.0.1:9300}, bound_addresses {[fe80::1]:9300}, {[::1]:9300}, {127.0.0.1:9300}
[2018-02-04T17:28:05,130][INFO ][o.e.c.s.MasterService    ] [HcAbRrt] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {HcAbRrt}{HcAbRrt4RVqvazgkI-W18Q}{sLMjeORSTb-oR3nm1ZFjNQ}{127.0.0.1}{127.0.0.1:9300}
[2018-02-04T17:28:05,144][INFO ][o.e.c.s.ClusterApplierService] [HcAbRrt] new_master {HcAbRrt}{HcAbRrt4RVqvazgkI-W18Q}{sLMjeORSTb-oR3nm1ZFjNQ}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {HcAbRrt}{HcAbRrt4RVqvazgkI-W18Q}{sLMjeORSTb-oR3nm1ZFjNQ}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-02-04T17:28:05,203][INFO ][o.e.h.n.Netty4HttpServerTransport] [HcAbRrt] publish_address {127.0.0.1:9200}, bound_addresses {[fe80::1]:9200}, {[::1]:9200}, {127.0.0.1:9200}
[2018-02-04T17:28:05,203][INFO ][o.e.n.Node               ] [HcAbRrt] started
[2018-02-04T17:28:05,207][INFO ][o.e.g.GatewayService     ] [HcAbRrt] recovered [0] indices into cluster_state

启动成功!

4、在浏览器请求  127.0.0.1:9200

{
  "name" : "HcAbRrt",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "saU-coKOQpW20NJKg_zzfA",
  "version" : {
    "number" : "6.1.0",
    "build_hash" : "c0c1ba0",
    "build_date" : "2017-12-12T12:32:54.550Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

 

以上是关于elasticsearch启动报错:can not run elasticsearch as root的主要内容,如果未能解决你的问题,请参考以下文章

es启动报RuntimeException: can not run elasticsearch as root解决方法

es启动报RuntimeException: can not run elasticsearch as root解决方法

elasticsearch: can not run elasticsearch as root

Zookeeper启动失败,报错 can not open chanel to 2

kibana启动报错 Elasticsearch cluster did not respond with license information

springboot-elasticsearch项目启动报错:'elasticsearchTemplate' that could not be found