elasticsearch 7.14叢集搭建
下載安裝elasticsearch
yum -y install java #安裝java環境
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.0-x86_64.rpm
yum -y install elasticsearch-7.14.0-x86_64.rpm
調整核心引數
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
echo "vm.swappiness=0" >>/etc/sysctl.conf
sysctl -w vm.max_map_count=262144
sysctl -p
更改檔案描述符
echo "* - nofile 65536" >>/etc/security/limits.conf
echo '* soft nofile 819200' >> /etc/security/limits.conf
echo '* hard nofile 819200' >> /etc/security/limits.conf
echo '* soft nproc 2048' >> /etc/security/limits.conf
echo '* hard nproc 4096' >> /etc/security/limits.conf
echo '* hard memlock unlimited' >> /etc/security/limits.conf
echo '* soft memlock unlimited' >> /etc/security/limits.conf
修改配置檔案
vim /etc/elasticsearch/elasticsearch.yml
cat /etc/elasticsearch/elasticsearch.yml |grep ^[^#]
cluster.name: ELK-cluster #叢集名稱
node.name: elk-node2 #節點名稱
path.data: /var/lib/elasticsearch #資料儲存路徑
path.logs: /var/log/elasticsearch #日誌儲存路徑
bootstrap.memory_lock: true #服務啟動的時候鎖定足夠的記憶體, 防止資料寫入 swap
http.port: 9200 # 對外提供服務的埠,9300為叢集服務的埠
network.host: 192.168.81.137 #繫結節點ip
discovery.seed_hosts: ["192.168.81.137", "192.168.81.138","192.168.81.139"] #叢集中node 節點發現列表
cluster.initial_master_nodes: elk-node1 #初始化主節點
# 設定是否可以通過正則或者_all 刪除或者關閉索引庫, 預設 true 表示必須需要 顯式指定索引庫名稱,生產環境建議設定為 true,刪除索引庫的時候必須指定, 否則可能會誤刪索引庫中的索引庫。
action.destructive_requires_name: true
http.cors.enabled: true #開啟支援跨域訪問
http.cors.allow-origin: "*" #指定允許訪問範圍 這兩項配置為 安裝head外掛需要的配置
node.master: true # 指示某個節點是否符合成為主節點的條件。預設為true
node.data: true # 指示節點是否為資料節點。資料節點包含並管理索引的一部分。 預設為true
其他節點將配置檔案拷貝過去修改節點名稱即可
修改記憶體限制,並同步配置檔案
vim /usr/lib/systemd/system/elasticsearch.service #修改記憶體 限制
LimitMEMLOCK=infinity #無限制使用記憶體
systemctl daemon-reload
vim /etc/elasticsearch/jvm.options
-Xms2g
-Xmx2g
啟動並配置開機自啟
systemctl enable --now elasticsearch.service
測試叢集是否正常啟動 訪問ip:埠 例 192.168.81.137:9200 如下圖即為正常
檢視叢集狀態
[root@linux-host2 ~]# curl 192.168.81.138:9200/_cluster/health?pretty
{
"cluster_name" : "ELK-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 17,
"active_shards" : 34,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
檢視節點
[root@linux-host2 ~]# curl 192.168.81.138:9200/_cat/nodes
192.168.81.137 19 94 0 0.00 0.01 0.05 cdfhilmrstw - elk-node1
192.168.81.138 20 69 0 0.02 0.02 0.05 cdfhilmrstw * elk-node2 #帶*的即為主節點
192.168.81.139 31 78 0 0.00 0.01 0.05 cdfhilmrstw - elk-node3
docker 安裝 head外掛
docker run -d -p 9100:9100 mobz/elasticsearch-head:5