elasticsearch-7.7.0安裝集群環境


系統:centos7(x86_64)

版本:elasticsearch-7.7.0-linux-x86_64.tar.gz

主機node01:192.168.60.110

主機node02:192.168.60.120

主機node03:192.168.60.130

ElasticSearch: https://mirrors.huaweicloud.com/elasticsearch/?C=N&O=D
logstash: https://mirrors.huaweicloud.com/logstash/?C=N&O=D
kibana: https://mirrors.huaweicloud.com/kibana/?C=N&O=D
elasticsearch-analysis-ik: https://github.com/medcl/elasticsearch-analysis-ik/releases
cerebro: https://github.com/lmenezes/cerebro/releases

准備:關閉防火牆,關閉selinux,更改主機名,主機名與ip地址映射,機器重啟,免密碼登錄,時鍾同步,安裝jdk

 

1.三台服務器配置環境

vi /etc/security/limits.conf   命令
#在后面添加

* soft nofile 65537
* hard nofile 65537
* soft nproc 65537
* hard nproc 65537
* hard memlock unlimited
* soft memlock unlimited

切換到root用戶:
在   /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144

立即生效命令:
sysctl -p
 vi /etc/systemd/system.conf   命令

  DefaultLimitNOFILE=65536
  DefaultLimitNPROC=32000
  DefaultLimitMEMLOCK=infinity

備注:修改好三個配置文件之后,重新連接secureCRT或者重新連接xshell生效
需要保存、退出、重新登錄xshell才可生效。

2.上傳安裝包解壓分發

三台服務器創建文件夾

mkdir -p /export/servers/es/

192.168.60.110服務器上傳tar.gz包

tar -zxvf elasticsearch-7.7.0-linux-x86_64.tar.gz -C /export/servers/es/

192.168.60.110復制兩個實例

cp -r elasticsearch-7.7.0/ elasticsearch-7.7.0_r1
cp -r elasticsearch-7.7.0/ elasticsearch-7.7.0_r2

192.168.60.110創建logs文件夾和datas文件夾

mkdir -p /export/servers/es/elasticsearch-7.7.0_r1/datas
mkdir -p /export/servers/es/elasticsearch-7.7.0_r1/logs

mkdir -p /export/servers/es/elasticsearch-7.7.0_r2/datas
mkdir -p /export/servers/es/elasticsearch-7.7.0_r2/logs

192.168.60.110分發包到192.168.60.120和192.168.60.130上

scp -r /export/servers/es/elasticsearch-7.7.0_r1 root@192.168.60.120:/export/servers/es/
scp -r /export/servers/es/elasticsearch-7.7.0_r2 root@192.168.60.120:/export/servers/es/

scp -r /export/servers/es/elasticsearch-7.7.0_r1 root@192.168.60.130:/export/servers/es/
scp -r /export/servers/es/elasticsearch-7.7.0_r2 root@192.168.60.130:/export/servers/es/

3.創建普通用戶

ES不能使用root用戶來啟動,必須使用普通用戶來安裝啟動。

三台服務器執行:

useradd elastic
chown -R elastic:elastic /export/servers/es

4.配置elasticsearch配置文件

192.168.60.110  /export/servers/es/elasticsearch-7.7.0_r1/config/elasticsearch.yml

#配置es的集群名稱
cluster.name: cloud_es
#節點名
node.name: node01_r1

#主節點
node.master: true
#數據節點
node.data: true

#數據存放目錄,可以設置多個存儲路徑,用逗號隔開
path.data: /export/servers/es/elasticsearch-7.7.0_r1/datas
#日志存放目錄,可以設置多個日志路徑,用逗號隔開
path.logs: /export/servers/es/elasticsearch-7.7.0_r1/logs

#服務器ip
network.host: ${HOSTNAME}
#設置節點間交互的tcp端口,默認是9300
transport.tcp.port: 9301
#設置對外服務的http端口,默認為9200
http.port: 9201

#設置這個參數來保證集群中的節點可以知道其它N個有master資格的節點。默認為1,對於大的集群來說,可以設置大一點的值(2-4)
discovery.zen.minimum_master_nodes: 2
#自動發現設置,配置之后集群的主機之間可以自動發現。對應舊版中的discovery.zen.ping.unicast.hosts。
discovery.seed_hosts: ["node01.hadoop.com:9301", "node02.hadoop.com:9301", "node03.hadoop.com:9301", "node01.hadoop.com:9302", "node02.hadoop.com:9302", "node03.hadoop.com:9302"]
#設置一系列符合主節點條件的節點的主機名或 IP 地址來引導啟動集群。如果手動設置了node.name,還可以設置為此節點的名稱。
cluster.initial_master_nodes: ["node01_r1"] # 確保當前節點是主節點

#是否支持跨域,默認為false
http.cors.enabled: true
#當設置允許跨域,默認為*,表示支持所有域名,
http.cors.allow-origin: "*"

#默認為false,這項使用默認配置,會導致硬盤頻繁讀,IOPS變高。設置true鎖定物理內存地址,防止es內存被交換出去,也就是避免es使用swap交換分區。
bootstrap.memory_lock: true
#開啟seccomp安全機制,seccomp能使一個進程進入到一種“安全”運行模式,該模式下的進程只能調用4種系統調用(system call),即 read(), write(), exit() 和 sigreturn(),否則進程便會被終止。
#centos6.x操作系統不支持SecComp只能為false,centos7.x操作系統可以設置成true
bootstrap.system_call_filter: true

#默認值是false,如果設置為true,那么就不允許將一個primary shard和replica shard分配到同一個物理機上,也許這個物理機上啟動了多個es實例。
cluster.routing.allocation.same_shard.host: true
#設置一台機子能運行的節點數目,一般采用默認的1即可,因為我們一般也只在一台機子上部署一個節點。
node.max_local_storage_nodes: 2

192.168.60.110  /export/servers/es/elasticsearch-7.7.0_r2/config/elasticsearch.yml

#配置es的集群名稱
cluster.name: cloud_es
#節點名
node.name: node01_r2

#主節點
node.master: true
#數據節點
node.data: true

#數據存放目錄,可以設置多個存儲路徑,用逗號隔開
path.data: /export/servers/es/elasticsearch-7.7.0_r2/datas
#日志存放目錄,可以設置多個日志路徑,用逗號隔開
path.logs: /export/servers/es/elasticsearch-7.7.0_r2/logs

#服務器ip
network.host: ${HOSTNAME}
#設置節點間交互的tcp端口,默認是9300
transport.tcp.port: 9302
#設置對外服務的http端口,默認為9200
http.port: 9202

#設置這個參數來保證集群中的節點可以知道其它N個有master資格的節點。默認為1,對於大的集群來說,可以設置大一點的值(2-4)
discovery.zen.minimum_master_nodes: 2
#自動發現設置,配置之后集群的主機之間可以自動發現。對應舊版中的discovery.zen.ping.unicast.hosts。
discovery.seed_hosts: ["node01.hadoop.com:9301", "node02.hadoop.com:9301", "node03.hadoop.com:9301", "node01.hadoop.com:9302", "node02.hadoop.com:9302", "node03.hadoop.com:9302"]
#設置一系列符合主節點條件的節點的主機名或 IP 地址來引導啟動集群。如果手動設置了node.name,還可以設置為此節點的名稱。
cluster.initial_master_nodes: ["node01_r1", "node01_r2", "node02_r1", "node02_r2", "node03_r1", "node03_r2"] # 確保當前節點是主節點

#是否支持跨域,默認為false
http.cors.enabled: true
#當設置允許跨域,默認為*,表示支持所有域名,
http.cors.allow-origin: "*"

#默認為false,這項使用默認配置,會導致硬盤頻繁讀,IOPS變高。設置true鎖定物理內存地址,防止es內存被交換出去,也就是避免es使用swap交換分區。
bootstrap.memory_lock: true
#開啟seccomp安全機制,seccomp能使一個進程進入到一種“安全”運行模式,該模式下的進程只能調用4種系統調用(system call),即 read(), write(), exit() 和 sigreturn(),否則進程便會被終止。
#centos6.x操作系統不支持SecComp只能為false,centos7.x操作系統可以設置成true
bootstrap.system_call_filter: true

#默認值是false,如果設置為true,那么就不允許將一個primary shard和replica shard分配到同一個物理機上,也許這個物理機上啟動了多個es實例。
cluster.routing.allocation.same_shard.host: true
#設置一台機子能運行的節點數目,一般采用默認的1即可,因為我們一般也只在一台機子上部署一個節點。
node.max_local_storage_nodes: 2

192.168.60.120  /export/servers/es/elasticsearch-7.7.0_r1/config/elasticsearch.yml

#配置es的集群名稱
cluster.name: cloud_es
#節點名
node.name: node02_r1

#主節點
node.master: true
#數據節點
node.data: true

#數據存放目錄,可以設置多個存儲路徑,用逗號隔開
path.data: /export/servers/es/elasticsearch-7.7.0_r1/datas
#日志存放目錄,可以設置多個日志路徑,用逗號隔開
path.logs: /export/servers/es/elasticsearch-7.7.0_r1/logs

#服務器ip
network.host: ${HOSTNAME}
#設置節點間交互的tcp端口,默認是9300
transport.tcp.port: 9301
#設置對外服務的http端口,默認為9200
http.port: 9201

#設置這個參數來保證集群中的節點可以知道其它N個有master資格的節點。默認為1,對於大的集群來說,可以設置大一點的值(2-4)
discovery.zen.minimum_master_nodes: 2
#自動發現設置,配置之后集群的主機之間可以自動發現。對應舊版中的discovery.zen.ping.unicast.hosts。
discovery.seed_hosts: ["node01.hadoop.com:9301", "node02.hadoop.com:9301", "node03.hadoop.com:9301", "node01.hadoop.com:9302", "node02.hadoop.com:9302", "node03.hadoop.com:9302"]
#設置一系列符合主節點條件的節點的主機名或 IP 地址來引導啟動集群。如果手動設置了node.name,還可以設置為此節點的名稱。
cluster.initial_master_nodes: ["node01_r1", "node01_r2", "node02_r1", "node02_r2", "node03_r1", "node03_r2"] # 確保當前節點是主節點

#是否支持跨域,默認為false
http.cors.enabled: true
#當設置允許跨域,默認為*,表示支持所有域名,
http.cors.allow-origin: "*"

#默認為false,這項使用默認配置,會導致硬盤頻繁讀,IOPS變高。設置true鎖定物理內存地址,防止es內存被交換出去,也就是避免es使用swap交換分區。
bootstrap.memory_lock: true
#開啟seccomp安全機制,seccomp能使一個進程進入到一種“安全”運行模式,該模式下的進程只能調用4種系統調用(system call),即 read(), write(), exit() 和 sigreturn(),否則進程便會被終止。
#centos6.x操作系統不支持SecComp只能為false,centos7.x操作系統可以設置成true
bootstrap.system_call_filter: true

#默認值是false,如果設置為true,那么就不允許將一個primary shard和replica shard分配到同一個物理機上,也許這個物理機上啟動了多個es實例。
cluster.routing.allocation.same_shard.host: true
#設置一台機子能運行的節點數目,一般采用默認的1即可,因為我們一般也只在一台機子上部署一個節點。
node.max_local_storage_nodes: 2

192.168.60.120  /export/servers/es/elasticsearch-7.7.0_r2/config/elasticsearch.yml

#配置es的集群名稱
cluster.name: cloud_es
#節點名
node.name: node02_r2

#主節點
node.master: true
#數據節點
node.data: true

#數據存放目錄,可以設置多個存儲路徑,用逗號隔開
path.data: /export/servers/es/elasticsearch-7.7.0_r2/datas
#日志存放目錄,可以設置多個日志路徑,用逗號隔開
path.logs: /export/servers/es/elasticsearch-7.7.0_r2/logs

#服務器ip
network.host: ${HOSTNAME}
#設置節點間交互的tcp端口,默認是9300
transport.tcp.port: 9302
#設置對外服務的http端口,默認為9200
http.port: 9202

#設置這個參數來保證集群中的節點可以知道其它N個有master資格的節點。默認為1,對於大的集群來說,可以設置大一點的值(2-4)
discovery.zen.minimum_master_nodes: 2
#自動發現設置,配置之后集群的主機之間可以自動發現。對應舊版中的discovery.zen.ping.unicast.hosts。
discovery.seed_hosts: ["node01.hadoop.com:9301", "node02.hadoop.com:9301", "node03.hadoop.com:9301", "node01.hadoop.com:9302", "node02.hadoop.com:9302", "node03.hadoop.com:9302"]
#設置一系列符合主節點條件的節點的主機名或 IP 地址來引導啟動集群。如果手動設置了node.name,還可以設置為此節點的名稱。
cluster.initial_master_nodes: ["node01_r1", "node01_r2", "node02_r1", "node02_r2", "node03_r1", "node03_r2"] # 確保當前節點是主節點

#是否支持跨域,默認為false
http.cors.enabled: true
#當設置允許跨域,默認為*,表示支持所有域名,
http.cors.allow-origin: "*"

#默認為false,這項使用默認配置,會導致硬盤頻繁讀,IOPS變高。設置true鎖定物理內存地址,防止es內存被交換出去,也就是避免es使用swap交換分區。
bootstrap.memory_lock: true
#開啟seccomp安全機制,seccomp能使一個進程進入到一種“安全”運行模式,該模式下的進程只能調用4種系統調用(system call),即 read(), write(), exit() 和 sigreturn(),否則進程便會被終止。
#centos6.x操作系統不支持SecComp只能為false,centos7.x操作系統可以設置成true
bootstrap.system_call_filter: true

#默認值是false,如果設置為true,那么就不允許將一個primary shard和replica shard分配到同一個物理機上,也許這個物理機上啟動了多個es實例。
cluster.routing.allocation.same_shard.host: true
#設置一台機子能運行的節點數目,一般采用默認的1即可,因為我們一般也只在一台機子上部署一個節點。
node.max_local_storage_nodes: 2

192.168.60.130  /export/servers/es/elasticsearch-7.7.0_r1/config/elasticsearch.yml

#配置es的集群名稱
cluster.name: cloud_es
#節點名
node.name: node03_r1

#主節點
node.master: true
#數據節點
node.data: true

#數據存放目錄,可以設置多個存儲路徑,用逗號隔開
path.data: /export/servers/es/elasticsearch-7.7.0_r1/datas
#日志存放目錄,可以設置多個日志路徑,用逗號隔開
path.logs: /export/servers/es/elasticsearch-7.7.0_r1/logs

#服務器ip
network.host: ${HOSTNAME}
#設置節點間交互的tcp端口,默認是9300
transport.tcp.port: 9301
#設置對外服務的http端口,默認為9200
http.port: 9201

#設置這個參數來保證集群中的節點可以知道其它N個有master資格的節點。默認為1,對於大的集群來說,可以設置大一點的值(2-4)
discovery.zen.minimum_master_nodes: 2
#自動發現設置,配置之后集群的主機之間可以自動發現。對應舊版中的discovery.zen.ping.unicast.hosts。
discovery.seed_hosts: ["node01.hadoop.com:9301", "node02.hadoop.com:9301", "node03.hadoop.com:9301", "node01.hadoop.com:9302", "node02.hadoop.com:9302", "node03.hadoop.com:9302"]
#設置一系列符合主節點條件的節點的主機名或 IP 地址來引導啟動集群。如果手動設置了node.name,還可以設置為此節點的名稱。
cluster.initial_master_nodes: ["node01_r1", "node01_r2", "node02_r1", "node02_r2", "node03_r1", "node03_r2"] # 確保當前節點是主節點

#是否支持跨域,默認為false
http.cors.enabled: true
#當設置允許跨域,默認為*,表示支持所有域名,
http.cors.allow-origin: "*"

#默認為false,這項使用默認配置,會導致硬盤頻繁讀,IOPS變高。設置true鎖定物理內存地址,防止es內存被交換出去,也就是避免es使用swap交換分區。
bootstrap.memory_lock: true
#開啟seccomp安全機制,seccomp能使一個進程進入到一種“安全”運行模式,該模式下的進程只能調用4種系統調用(system call),即 read(), write(), exit() 和 sigreturn(),否則進程便會被終止。
#centos6.x操作系統不支持SecComp只能為false,centos7.x操作系統可以設置成true
bootstrap.system_call_filter: true

#默認值是false,如果設置為true,那么就不允許將一個primary shard和replica shard分配到同一個物理機上,也許這個物理機上啟動了多個es實例。
cluster.routing.allocation.same_shard.host: true
#設置一台機子能運行的節點數目,一般采用默認的1即可,因為我們一般也只在一台機子上部署一個節點。
node.max_local_storage_nodes: 2

192.168.60.130  /export/servers/es/elasticsearch-7.7.0_r2/config/elasticsearch.yml

#配置es的集群名稱
cluster.name: cloud_es
#節點名
node.name: node03_r2

#主節點
node.master: true
#數據節點
node.data: true

#數據存放目錄,可以設置多個存儲路徑,用逗號隔開
path.data: /export/servers/es/elasticsearch-7.7.0_r2/datas
#日志存放目錄,可以設置多個日志路徑,用逗號隔開
path.logs: /export/servers/es/elasticsearch-7.7.0_r2/logs

#服務器ip
network.host: ${HOSTNAME}
#設置節點間交互的tcp端口,默認是9300
transport.tcp.port: 9302
#設置對外服務的http端口,默認為9200
http.port: 9202

#設置這個參數來保證集群中的節點可以知道其它N個有master資格的節點。默認為1,對於大的集群來說,可以設置大一點的值(2-4)
discovery.zen.minimum_master_nodes: 2
#自動發現設置,配置之后集群的主機之間可以自動發現。對應舊版中的discovery.zen.ping.unicast.hosts。
discovery.seed_hosts: ["node01.hadoop.com:9301", "node02.hadoop.com:9301", "node03.hadoop.com:9301", "node01.hadoop.com:9302", "node02.hadoop.com:9302", "node03.hadoop.com:9302"]
#設置一系列符合主節點條件的節點的主機名或 IP 地址來引導啟動集群。如果手動設置了node.name,還可以設置為此節點的名稱。
cluster.initial_master_nodes: ["node01_r1", "node01_r2", "node02_r1", "node02_r2", "node03_r1", "node03_r2"] # 確保當前節點是主節點

#是否支持跨域,默認為false
http.cors.enabled: true
#當設置允許跨域,默認為*,表示支持所有域名,
http.cors.allow-origin: "*"

#默認為false,這項使用默認配置,會導致硬盤頻繁讀,IOPS變高。設置true鎖定物理內存地址,防止es內存被交換出去,也就是避免es使用swap交換分區。
bootstrap.memory_lock: true
#開啟seccomp安全機制,seccomp能使一個進程進入到一種“安全”運行模式,該模式下的進程只能調用4種系統調用(system call),即 read(), write(), exit() 和 sigreturn(),否則進程便會被終止。
#centos6.x操作系統不支持SecComp只能為false,centos7.x操作系統可以設置成true
bootstrap.system_call_filter: true

#默認值是false,如果設置為true,那么就不允許將一個primary shard和replica shard分配到同一個物理機上,也許這個物理機上啟動了多個es實例。
cluster.routing.allocation.same_shard.host: true
#設置一台機子能運行的節點數目,一般采用默認的1即可,因為我們一般也只在一台機子上部署一個節點。
node.max_local_storage_nodes: 2

5.啟動elaticsearch服務

切換到elastic用戶執行啟動命令,或者在前面加上 nohup 后台運行,三台服務器分別執行:

/export/servers/es/elasticsearch-7.7.0_r1/bin/elasticsearch 2>&1 &
/export/servers/es/elasticsearch-7.7.0_r2/bin/elasticsearch 2>&1 &

或者使用啟動腳本:

#!/bin/bash

/usr/bin/su - elastic -c '/usr/local/elasticsearch-7.3.0-cluster-node1/bin/elasticsearch -p /tmp/elasticsearch_9200_pid -d'
/usr/bin/su - elastic -c '/usr/local/elasticsearch-7.3.0-cluster-node2/bin/elasticsearch -p /tmp/elasticsearch_9201_pid -d'
/usr/bin/su - elastic -c '/usr/local/elasticsearch-7.3.0-cluster-node3/bin/elasticsearch -p /tmp/elasticsearch_9202_pid -d'

關閉腳本:

#!/bin/bash

kill -9 `ps -u elastic|awk '{print $1}'`

重啟腳本:

./elasticsearch -d

6.啟動成功

 

 

 

 

 

 

 

 

 

 7.查看集群狀態

http://192.168.60.110:9201/_cat/health?v

 正常

8.建議

如果一個節點即有成為主節點的資格,又存儲數據,這個時候如果某個節點被選舉成為了真正的主節點,那么他還要存儲數據,這樣對於這個節點的壓力就比較大了。elasticsearch默認每個節點都是這樣的配置,在測試環境下這樣做沒問題。實際工作中建議不要這樣設置,這樣相當於主節點和數據節點的角色混合到一塊了。

1. 生產環境一台服務器部署兩個節點, 一個只為主節點 一個只為數據節點。或者3台以上主節點,其他全為數據節點。

9.ES開機自啟

/etc/init.d/startES

#!/bin/bash
#
# chkconfig: 2345 55 25
# description:start ES instance


host=$(hostname)

time=$( date '+%Y-%m-%d %H:%M:%S')
echo  "$@ $host $time elasticsearch-6.1.0" >> /root/powerOn.log
su - elastic -c '/usr/local/elasticsearch-6.1.0/bin/elasticsearch -d'

time=$( date '+%Y-%m-%d %H:%M:%S')
echo  "$@ $host $time cerebro " >> /root/powerOn.log
su - elastic -c "nohup /usr/local/cerebro-0.7.2/bin/cerebro >/dev/null &"


time=$( date '+%Y-%m-%d %H:%M:%S')
echo  "$@ $host $time kibana" >> /root/powerOn.log
su - elastic -c "nohup /usr/local/kibana-6.1.0-linux-x86_64/bin/kibana >/dev/null &"


time=$( date '+%Y-%m-%d %H:%M:%S')
echo  "$@ $host $time kafka-manager" >> /root/powerOn.log
num=$(netstat -ntlp |grep 9997 |wc -l)
RUNNING_FILE=/usr/local/kafka-manager-1.3.3.7/RUNNING_PID
if [[ $num -eq  0 ]];then

  if [ -f $RUNNING_FILE ];then
    rm $RUNNING_FILE
  fi

   nohup /usr/local/kafka-manager-1.3.3.7/bin/kafka-manager -Dconfig.file=/usr/local/kafka-manager-1.3.3.7/conf/application.conf -Dhttp.port=9997 >/dev/null 2>&1 &
fi

 


免責聲明!

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



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