1. 程式人生 > >elasticsearch: can not run elasticsearch as root

elasticsearch: can not run elasticsearch as root

touch ret recover elastic data url enable pdu [1]

進入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-xr-x@ 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-xr-x@ 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