部署環境說明:
操作系統:CentOS7
elasticsearch版本:elasticsearch-5.6.4.tar.gz
JDK版本:jdk1.8.0_144
服務器:
192.168.1.240(主節點、數據節點)
192.168.1.241(主節點、數據節點)
192.168.1.242(數據節點)
部署步驟:
elasticsearch5.6.4必需要jdk1.8版本,后續簡稱es
部署前需要首先安裝jdk1.8,然后設置jdk的環境變量,這里就不贅述了
當然如果不想改變原先jdk的環境變量,比如原先服務器上已經安裝了其他版本的jdk,下文會介紹另外一種方式
1、修改內核參數,如果不修改內核參數后續啟動es會報各種錯誤
vi /etc/security/limits.conf 添加如下內容(也可以根據實際設定為其他值)
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
vi /etc/sysctl.conf 添加如下內容
vm.max_map_count=655360
執行 sysctl -p 使配置生效
2、在elasticsearch官網(https://www.elastic.co/downloads/elasticsearch)下載elasticsearch-5.6.4.tar.gz
放到/opt下,解壓縮
tar -xvzf elasticsearch-5.6.4.tar.gz
生成文件夾 elasticsearch-5.6.4
3、建立運行es的用戶(es不允許以root用戶執行,沒有找到其他的解決方案這個版本)
adduser elas
passwd elas 設定密碼
chown -R elas /opt/elasticsearch-5.6.4 將文件夾的所有權給elas用戶
4、修改配置文件,這個步驟在三臺服務器上執行不同的操作
在192.168.1.240 上
vi /opt/elasticsearch-5.6.4/config/elasticsearch.yml
增加如下配置
#設置集群的名稱
cluster.name: elas-1
#設置當前節點的名稱
node.name: hadoop
#設置當前節點的HOST
network.host: 192.168.1.240
#設置當前節點為主節點
node.master: true
#設置當前節點為數據節點
node.data: true
#允許跨源REST請求,后續安裝head插件需要此參數
http.cors.enabled: true
#設置跨源的REST來自何處,*表示所有
http.cors.allow-origin: "*"
#集群發現模式,這里使用的是單播,多播在某些環境下不受支持,比如阿里云
discovery.zen.ping.unicast.hosts: ["192.168.1.240","192.168.1.241","192.168.1.242"]
在192.168.1.241上
cluster.name: elas-1
node.name: hadoop2
network.host: 192.168.1.241
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["192.168.1.240","192.168.1.241","192.168.1.242"]
在192.168.1.242上
cluster.name: elas-1
node.name: hadoop3
network.host: 192.168.1.242
#不是主節點
node.master: false
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["192.168.1.240","192.168.1.241","192.168.1.242"]
5、啟動
切換到elas用戶
su - elas
在三臺服務器是上分別執行命令
cd /opt/elasticsearch-5.6.4
bin/elasticsearch
上文說過如果沒有設置jdk1.8的環境變量,可以修改一下這個啟動腳本,在開始處增加jdk1.8的JAVA_HOME
export JAVA_HOME=/opt/jdk1.8.0_144
啟動成功后,會有如下的日志輸出
通過瀏覽器可以訪問其中任何一臺服務器,也可以訪問查看集群狀態
http://192.168.1.240:9200/_cluster/health?pretty=true
可以查看集群的狀態如下
下一篇將介紹head插件的安裝