elasticsearch單機多節(jié)點集群搭建
elasticsearch7開始不支持單機多節(jié)點部署
環(huán)境準備
-
centos服務器兩臺:10.188.131.247、10.20.148.122
-
elasticsearch-6.8.23、kibana-6.8.23安裝包下載(下載地址:https://www.elastic.co/cn/downloads/past-releases#elasticsearch)
-
新增es用戶(elasticsearch不能用root用戶啟動)
groupadd es useradd -g es -m es passwd es
集群搭建
-
集群概覽:3個master節(jié)點,3個數(shù)據(jù)節(jié)點
服務器 節(jié)點名稱 是否為主節(jié)點 是否為數(shù)據(jù)節(jié)點 10.20.148.122 node-1 true true 10.20.148.122 node-2 true true 10.20.148.122 node-3 true true -
解壓elasticsearch-6.8.23.tar.gz
tar -zxvf elasticsearch-6.8.23.tar.gz mv elasticsearch-6.8.23 elasticsearch
-
復制為node-1
cp -r elasticsearch node-1 # 創(chuàng)建數(shù)據(jù)儲存目錄 cd node-1 mkdir -p data # 創(chuàng)建日志儲存目錄 mkdir -p logs # 創(chuàng)建歸檔目錄 mkdir -p es_snapshot
-
配置elasticsearch.yml(以node-1節(jié)點為例)
vim /home/es/node-1/config/elasticsearch.yml
注意:每個配置項冒號后面需要空一格,否則啟動會報錯
#集群的名稱,不同的節(jié)點通過相同集群名稱來組裝集群 cluster.name: es-cluster-122 #節(jié)點名稱,每個節(jié)點配置不同名稱 node.name: node-1 #是否主節(jié)點 node.master: true #是否數(shù)據(jù)節(jié)點 node.data: true #單機最大節(jié)點數(shù) node.max_local_storage_nodes: 3 #索引數(shù)據(jù)的存儲路徑 path.data: /data2/es/node-1/data #日志文件的存儲路徑 path.logs: /data2/es/node-1/logs #綁定的ip地址 network.host: 10.20.148.122 #設置對外服務的http端口,默認為9200 http.port: 9200 #設置節(jié)點間交互的tcp端口,默認是9300 transport.tcp.port: 9300 transport.tcp.compress: true #設置集群中節(jié)點的初始列表,可以通過這些節(jié)點來自動發(fā)現(xiàn)新加入集群的節(jié)點 discovery.zen.ping.unicast.hosts: ["10.20.148.122:9300", "10.20.148.122:9301","10.20.148.122:9302"] #防止腦裂現(xiàn)象,如果沒有這種設置,遭受網(wǎng)絡故障的集群就有可能將集群分成兩個獨立的集群 - 這將導致數(shù)據(jù)丟失當節(jié)點<=2時設置為1,>2時官方的推薦值是(N/2)+1 discovery.zen.minimum_master_nodes: 2 #啟動時鎖定內(nèi)存,設置為true來鎖住內(nèi)存。因為內(nèi)存交換到磁盤對服務器性能來說是致命的,當jvm開始swapping時es的效率會降低,所以要保證它不swap bootstrap.memory_lock: true bootstrap.system_call_filter: false #========使用head插件的時候需要添加這3個配置======== http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type #action.destructive_requires_name: true #防止同一個shard的主副本存在同一個物理機上 cluster.routing.allocation.same_shard.host: true #es 歸檔倉庫路徑 path.repo: ["/data2/es/node-1/es_snapshot"] thread_pool.write.queue_size: 8192
-
創(chuàng)建node-2、node3節(jié)點
cp -r node-1 node-2 cp -r node-1 node-3
node-2,node-3節(jié)點配置與node-1類似,修改node.name、path.data、path.log、http.port、transport.tcp.port、path.repo等配置為對應值即可
-
如果內(nèi)存空間不足,需修改jvm.options中配置
vim /home/es/node-1/config/jvm.options #默認是1g官方建議對jvm進行一些修改,不然很容易出現(xiàn)OOM,參考官網(wǎng)改參數(shù)配置最好不要超過內(nèi)存的50% -Xms750m -Xmx750m
-
啟動各個節(jié)點
#!/bin/bash WORKDIR=$(dirname $0) nohup $WORKDIR/node-1/bin/elasticsearch -d 2>&1 & nohup $WORKDIR/node-2/bin/elasticsearch -d 2>&1 & nohup $WORKDIR/node-3/bin/elasticsearch -d 2>&1 &
如果出現(xiàn)
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
解決辦法是修改jvm.options文件配置
vim /home/es/node-1/config/jvm.options
,將-XX:+UseConcMarkSweepGC 改為 -XX:+UseG1GC
-
查看節(jié)點情況
curl -XGET 'http://10.20.148.122:9200/_cat/nodes?pretty' curl -XGET 'http://10.20.148.122:9200/_cat/health?v'
kibana可視化平臺
-
解壓kibana-6.8.23-linux-x86_64.tar.gz
tar -zxvf kibana-6.8.23-linux-x86_64.tar.gz mv kibana-6.8.23-linux-x86_64.tar.gz kibana
-
配置kibana.yml
cd kibana/config/ vim kibana.yml # 修改端口 server.port: 5601 # 修改IP server.host: "10.188.131.247" # 修改監(jiān)控的es集群地址 elasticsearch.hosts: ["http://10.20.148.122:9200"]
-
啟動
cd kibana/bin/ nohup ./kibana & # 查看進程 lsof -i:5601/netstat -tunlp|grep 5601
-
可視化
http://10.188.131.247:5601/
文章來源:http://www.zghlxwxcb.cn/news/detail-527523.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-527523.html
到了這里,關于elasticsearch單機多節(jié)點集群搭建的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!