elasticsearch不能以root啟動並執行問題

來源:互聯網
上載者:User

當我們在使用elasticsearch的時候,如果是以root許可權來執行elasticsearch

./elasticsearch

則會有以下報錯

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

這是出於系統安全考慮設定的條件。由於Elasticsearch可以接收使用者輸入的指令碼並且執行,為了系統安全考慮,
建議建立一個單獨的使用者用來運行Elasticsearch

建立elsearch使用者組及elsearch使用者

groupadd elsearchuseradd elsearch -g elsearch -p elasticsearch

更改elasticsearch檔案夾及內部檔案的所屬使用者及組為elsearch:elsearch

chown -R elsearch:elsearch  elasticsearch

elasticsearch為你elasticsearch的目錄名稱

切換到elsearch使用者再啟動

su elsearch #切換賬戶cd elasticsearch/bin #進入你的elasticsearch目錄下的bin目錄./elasticsearch

啟動後會列印正常開機記錄資訊如下

[elsearch@localhost elasticsearch-2.4.0]$ ./bin/elasticsearch [2016-11-30 09:00:07,658][INFO ][node                     ] [Black Bolt] version[2.4.0], pid[25504], build[ce9f0c7/2016-08-29T09:14:17Z][2016-11-30 09:00:07,674][INFO ][node                     ] [Black Bolt] initializing ...[2016-11-30 09:00:08,248][INFO ][plugins                  ] [Black Bolt] modules [lang-groovy, reindex, lang-expression], plugins [elasticsearch-analysis-ik, head], sites [head][2016-11-30 09:00:08,267][INFO ][env                      ] [Black Bolt] using [1] data paths, mounts [[/home (/dev/mapper/centos-home)]], net usable_space [172.1gb], net total_space [172.9gb], spins? [possibly], types [xfs][2016-11-30 09:00:08,267][INFO ][env                      ] [Black Bolt] heap size [990.7mb], compressed ordinary object pointers [true][2016-11-30 09:00:08,268][WARN ][env                      ] [Black Bolt] max file descriptors [4096] for elasticsearch process likely too low, consider increasing to at least [65536][2016-11-30 09:00:09,561][INFO ][ik-analyzer              ] [Dict Loading] ik/custom/mydict.dic[2016-11-30 09:00:09,579][INFO ][ik-analyzer              ] [Dict Loading] ik/custom/single_word_low_freq.dic[2016-11-30 09:00:09,589][INFO ][ik-analyzer              ] [Dict Loading] ik/custom/ext_stopword.dic[2016-11-30 09:00:09,935][INFO ][node                     ] [Black Bolt] initialized[2016-11-30 09:00:09,935][INFO ][node                     ] [Black Bolt] starting ...[2016-11-30 09:00:09,975][INFO ][transport                ] [Black Bolt] publish_address {172.17.0.1:9300}, bound_addresses {[::]:9300}[2016-11-30 09:00:09,979][INFO ][discovery                ] [Black Bolt] elasticsearch/YGWbxIWSRyejtiM4WqHwAA[2016-11-30 09:00:13,003][INFO ][cluster.service          ] [Black Bolt] new_master {Black Bolt}{YGWbxIWSRyejtiM4WqHwAA}{172.17.0.1}{172.17.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)[2016-11-30 09:00:13,010][INFO ][http                     ] [Black Bolt] publish_address {172.17.0.1:9200}, bound_addresses {[::]:9200}[2016-11-30 09:00:13,010][INFO ][node                     ] [Black Bolt] started[2016-11-30 09:00:13,323][INFO ][gateway                  ] [Black Bolt] recovered [1] indices into cluster_state[2016-11-30 09:00:15,576][INFO ][cluster.routing.allocation] [Black Bolt] Cluster health status changed from [RED] to [YELLOW] (reason: [shards started [[sports][2]] ...]).

之後如果再啟動的話(如果是以root許可權登入伺服器),只需要執行切換賬戶,然後運行elasticsearch就可以了

su elsearch #切換賬戶cd elasticsearch/bin #進入你的elasticsearch目錄下的bin目錄./elasticsearch

Elasticsearch後台啟動命令

./elasticsearch -d

查看後台命令是否啟動成功

ps aux|grep elasticsearch

結果

elsearch  3119  4.6  3.2 3535488 250876 pts/1  Sl   16:50   0:09 /opt/java/jdk1.7.0_75/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/home/py-project/elasticsearc-2.4.0 -cp /home/py-project/elasticsearch-2.4.0/lib/elasticsearch-2.4.0.jar:/home/py-project/elasticsearch-2.4.0/lib/* org.elasticsearch.bootstrap.Elasticsearch start -delsearch  3254  0.0  0.0 110224   916 pts/1    S+   16:54   0:00 grep --color=auto elasticsearch

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.