本文已三个节点(服务器)为例,准备三台服务器
tar -zxvf elasticsearch-8.4.1-linux-x86_64.tar.gz
创建用户:useradd es_user
设置密码:passwd es_user
# chmod是更改文件的权限
# chown是改改文件的属主与属组
# chgrp只是更改文件的属组。
chgrp -R es_user /usr/local/software/elk_test/elasticsearch-8.4.1
chown -R es_user /usr/local/software/elk_test/elasticsearch-8.4.1
chmod -R 777 /usr/local/software/elk_test/elasticsearch-8.4.1
在文件内容最后添加后面两行(切记*不能省略)
vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
在配置文件中改配置 最后一行上加上,执行 sysctl -p(立即生效)
vim /etc/sysctl.conf
vm.max_map_count=262144
vim config/jvm.options
-Xms1g
-Xmx1g
节点一
vim config/elasticsearch.yml
cluster.name: xdclass-cluster
node.name: node-1
path.data: /usr/local/software/elk_test/elasticsearch-8.4.1/data
path.logs: /usr/local/software/elk_test/elasticsearch-8.4.1/logs
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["172.31.101.11:9300","172.31.101.13:9300","172.31.101.12:9300"]
cluster.initial_master_nodes: ["172.31.101.11:9300","172.31.101.13:9300","172.31.101.12:9300"]
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
ingest.geoip.downloader.enabled: false
节点二
vim config/elasticsearch.yml
cluster.name: xdclass-cluster
node.name: node-2
path.data: /usr/local/software/elk_test/elasticsearch-8.4.1/data
path.logs: /usr/local/software/elk_test/elasticsearch-8.4.1/logs
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["172.31.101.11:9300","172.31.101.13:9300","172.31.101.12:9300"]
cluster.initial_master_nodes: ["172.31.101.11:9300","172.31.101.13:9300","172.31.101.12:9300"]
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
ingest.geoip.downloader.enabled: false
节点三
vim config/elasticsearch.yml
cluster.name: xdclass-cluster
node.name: node-3
path.data: /usr/local/software/elk_test/elasticsearch-8.4.1/data
path.logs: /usr/local/software/elk_test/elasticsearch-8.4.1/logs
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["172.31.101.11:9300","172.31.101.13:9300","172.31.101.12:9300"]
cluster.initial_master_nodes: ["172.31.101.11:9300","172.31.101.13:9300","172.31.101.12:9300"]
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
ingest.geoip.downloader.enabled: false
配置说明
discovery.seed_hosts参数:
cluster.initial_master_nodes参数:
功能:cluster.initial_master_nodes参数用于配置初始主节点的名称。
作用:当集群启动时,用于指定初始的主节点,以启动集群的选主过程。
配置:只需在初始启动的几个节点的elasticsearch.yml配置文件中设置该参数,列出节点名称。
注意
cluster.initial_master_nodes参数和discovery.seed_hosts参数之间的设置应该保持一致,
确保集群中的所有节点都能正确发现和加入。
切换到es_user用户启动, 进入bin目录下启动, &为后台启动,再次提示es消息时 Ctrl + c 跳出
./elasticsearch &
常见命令,可以用postman访问(网络安全组记得开发端口)
#查看集群健康情况
http://112.74.167.42:9200/_cluster/health
#查看分片情况
http://112.74.167.42:9200/_cat/shards?v=true&pretty
#查看节点分布情况
http://112.74.167.42:9200/_cat/nodes?v=true&pretty
#查看索引列表
http://112.74.167.42:9200/_cat/indices?v=true&pretty
集群状态说明
green:所有的主分片和副本分片都正常运行。
yellow:所有的主分片都正常运行,但有部分副本分片运行不正常。
red:主分片没能正常运行