java8安裝/elasticsearch安裝及運行失敗原因分析


 java 8 安裝

下載tar包:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

解壓java包到:
mkdir /usr/local/java
tar xzvf jdk-8u181-linux-x64.tar.gz

添加環境變量:
vim  /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_181
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
 
測試安裝是否成功:
 
 
 
 
elasticsearch 安裝
下載tar包:
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.tar.gz
 
解壓縮后直接運行即可
 
[root@elastic elasticsearch-6.4.0]# ./bin/elasticsearch -d
[2018-09-12T17:53:48,547][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:140) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.0.jar:6.4.0]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.4.0.jar:6.4.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.0.jar:6.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.0.jar:6.4.0]
... 6 more

運行報錯:can not run elasticsearch as root
 
root用戶不能執行elasticsearch,所以需要創建額外的用戶(參考https://my.oschina.net/topeagle/blog/591451?fromerr=mzOr2qzZ):
創建elsearch用戶組及elsearch用戶
[root@elastic elasticsearch-6.4.0]# groupadd elsearch
[root@elastic elasticsearch-6.4.0]# useradd elsearch -g elsearch -p elasticsearch
 
最好修改一下密碼,密碼elasticsearch也沒辦法直接用,因為是需要輸入加密后的字符串,加密后是elasticsearch的字符串我也不曉得是啥

[root@elastic elasticsearch-6.4.0]# passwd elsearch
Changing password for user elsearch.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

 
 
修改elasticsearch目錄權限
[root@elastic ~]# chown -R elsearch:elsearch elasticsearch-6.4.0
 
切換用戶
[root@elastic elasticsearch-6.4.0]# su elsearch
 
再次運行elasticsearch
[elsearch@elastic bin]$ ./elasticsearch -d
Error: Could not find or load main class org.elasticsearch.tools.java_version_checker.JavaVersionChecker
 
提示找不到java類,分析原因如下(參考https://discuss.elastic.co/t/error-could-not-find-or-load-main-class-org-elasticsearch-tools-javaversionchecker/82213):
調試運行
[elsearch@elastic bin]$ bash -x elasticsearch

 

發現問題是在cp jar包的時候,elsearch用戶沒有權限拷貝root目錄下的內容
 
 
把elasticsearch整個目錄移動到/home/elsearch下后,再次執行,成功

 

后面又報了兩個小錯誤,

ERROR: [2] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

修改配置即可

vi /etc/security/limits.conf  修改  * soft nofile 65536

vi /etc/sysctl.conf  增加  vm.max_map_count=262144
或者 sysctl -w vm.max_map_count=262144   sysctl -p
sysctl -a|grep vm.max_map_count 查看修改結果

 

改完后重啟,再運行elasticsearch可成功啟動

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM