介紹
采用rpm的方式安裝elasticsearch
纸俭,為什么叫避坑安裝慎恒。因?yàn)榻鈮喊惭b會(huì)有很多報(bào)錯(cuò),主要是與系統(tǒng)參數(shù)的沖突赎瞎,將會(huì)在附錄中貼出部分安裝包安裝的報(bào)錯(cuò)與解決辦法牌里。而采用rpm安裝方式直接載入到service中,利用service啟動(dòng)务甥,方便快捷牡辽。
環(huán)境
- linux: CentOS 7.2
- elasticsearch: elasticsearch-2.3.0.rpm(可下載歷史版本)
安裝過(guò)程
- 下載rpm包到服務(wù)器目錄
- rpm安裝并啟動(dòng)
# rpm -ivh elasticsearch-2.3.0.rpm
# sudo systemctl start elasticsearch.service
- 調(diào)試
# curl -XGET 'http://localhost:9200/'
出現(xiàn)一下信息代表成功:
{
"name" : "WfSYaKG",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "dGCAG-HkSv-hiNFfeqoV1A",
"version" : {
"number" : "2.3.0",
"build_hash" : "f9d9b74",
"build_date" : "2017-02-24T17:26:45.835Z",
"build_snapshot" : false,
"lucene_version" : "6.4.1"
},
"tagline" : "You Know, for Search"
}
你需要了解的目錄結(jié)構(gòu)
# whereis elasticsearch
elasticsearch: /etc/elasticsearch /usr/share/elasticsearch
可以看出elasticsearch的安裝目錄和配置文件所在目錄,因?yàn)閞pm安裝和安裝包解壓的目錄結(jié)構(gòu)是不一樣的敞临,為了方便運(yùn)維态辛,你需要記住:
- 啟動(dòng)文件目錄:
/usr/share/elasticsearch/bin
- 配置文件目錄:
/etc/elasticsearch
- 日志目錄:
/var/log/elasticsearch
安裝包解壓安裝報(bào)錯(cuò)與解決方案
- 啟動(dòng)內(nèi)存不足
$./bin/elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /data/elasticsearch-5.2.2/hs_err_pid26945.log
解決方案:調(diào)小啟動(dòng)內(nèi)存
# vi ${elasticsearch_HOME}/config/jvm.options
#-Xms2g
#-Xmx2g
-Xms512m
-Xmx512m
- 無(wú)法以root權(quán)限啟動(dòng)
[2017-03-23T16:22:17,193][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-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.2.2.jar:5.2.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:203) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-5.2.2.jar:5.2.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.2.2.jar:5.2.2]
... 6 more
解決方案:創(chuàng)建一個(gè)非root用戶并賦予目錄該用戶權(quán)限挺尿,再啟動(dòng)
# groupadd es
# useradd es -g es -p es
# chown es:es ${elasticsearch_HOME}/
# sudo su es
# ./bin/elasticsearch