環(huán)境準備
1.操作系統(tǒng):CentOS7.3
2.JDK1.8
安裝須知: elasticsearch-5.x的版本要求JDK1.8以上,所以安裝前北启,確保每臺服務器已經安裝JDK1.8及以上版本卜朗。
集群準備
- elasticsearch-5.6.3.tar.gz
- elasticsearch-HQ-master.zip
集群安裝
機器安排:
192.168.102.30(默認master node)
192.168.102.31
192.168.102.32
1. 下載elasticsearch(簡稱:ES)安裝包
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.3.tar.gz
# tar -zxvf elasticsearch-5.6.3.tar.gz
2. 修改配置文件
cd elasticsearch-5.6.3
vim config/elasticsearch.yml
添加以下配置(以下是192.168.102.30機器上的配置,其他機器對應修改):cluster.name: elasticsearch #集群里的每臺服務都要一致 node.name: node1 #每臺服務器節(jié)點都不一樣 node.master: true #是否為master network.host: 192.168.102.30 #本機ip http.port: 9200 #本機端口 transport.tcp.port: 9300 #Java client調用 discovery.zen.ping.unicast.hosts: ["192.168.102.30:9300","192.168.102.31:9300","192.168.102.32:9300"] path.data: /data/comm_apps/elasticsearch-5.6.3/data path.logs: /data/comm_apps/elasticsearch-5.6.3/logs
3. 配置足夠內存
# vim /data/comm_apps/elasticsearch-5.6.3/config/jvm.options
-Xms2g
-Xmx2g
4. 配置環(huán)境變量
# vim /etc/profile
export ES_HOME=/data/comm_apps/elasticsearch-5.6.3
# source /etc/profile
5.啟動elasticsearch
# cd elasticsearch-5.6.3 && /bin/elasticsearch -d
6.驗證服務是否啟動:
# netstat -tnl | grep 9200
或者 ps -ef | grep elasticsearch
常用插件安裝
head插件
目前都只安裝在192.168.102.30這臺服務器上
檢查node環(huán)境咕村,查看是否安裝命令:node -v
請確保已經安裝nodejs6.0版本以上
1. 下載插件包:
# wget https://codeload.github.com/mobz/elasticsearch-head/zip/master
解壓:
unzip elasticsearch-head-master.zip
2. 安裝插件:
# cd elasticsearch-head-master
# npm install
3. ElasticSearch整合elasticsearch-head插件:
# cd elasticsearch-5.6.3
# vim config/elasticsearch.yml
4. 在配置文件的最后加上運行head插件跨域訪問rest接口
http.cors.allowed:true
http.cors.allow-origin:"*"
5. 啟動插件:npm run start
輸出日志:Started connect web server on http://localhost:9100
表示啟動成功
能成功訪問http://localhost:9100
IK分詞插件
每臺機器都需要安裝
以插件形式安裝:
# cd elasticsearch-5.6.3
# ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.3/elasticsearch-analysis-ik-5.6.3.zip
訪問:
http://192.168.102.30:9200/_analyze?analyzer=ik_max_word&text=中華人民共和國&pretty=true
Elastic HQ插件
1. 下載
# wget https://github.com/royrusso/elasticsearch-HQ/archive/master.zip
2. 解壓
# unzip elasticsearch-HQ-master.zip
3. 安裝
# cd elasticsearch-HQ-master
4. 啟動
以下二選一:
# python -m SimpleHTTPServer(前臺啟動)
# nohup python -m SimpleHTTPServer > elasticsearch-HQ.file 2>&1 &(后臺啟動)
5. 驗證是否安裝成功
訪問http://192.168.102.30:8000/#cluster
問題解決
問題一
解決辦法:
錯誤一:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
辦法:修改/etc/security/limits.conf文件场钉,添加或修改如下行:
hard nofile 65536
soft nofile 65536
錯誤二:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
辦法:
原因:最大虛擬內存太小
root用戶執(zhí)行命令:
sysctl -w vm.max_map_count=262144
問題二
ES有執(zhí)行腳本的能力,因安全因素懈涛,不能在root用戶下運行逛万,強行運行會報如下錯誤:
org.elasticsearch.bootstrap.StartupException:
java.lang.RuntimeException: can not run elasticsearch as root
解決方案:
groupadd es #增加es組 useradd es -g es -p pwd #增加es用戶并附加到es組 chown -R es:es elasticsearch-5.6.3 #給目錄權限 su es #使用es用戶 ./bin/elasticsearch -d #后臺運行es