Skip to content
章节导航

ElasticSearch 8.x 高可用分布集群架构搭建实战

搭建实战

节点一

shell
vim config/elasticsearch.yml


cluster.name: shuofeng-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: ["192.168.253.101:9300","192.168.253.102:9300","192.168.253.103:9300"]
cluster.initial_master_nodes: ["192.168.253.101:9300","192.168.253.102:9300","192.168.253.103:9300"]
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
ingest.geoip.downloader.enabled: false

节点二

shell
vim config/elasticsearch.yml


cluster.name: shuofeng-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: ["192.168.253.101:9300","192.168.253.102:9300","192.168.253.103:9300"]
cluster.initial_master_nodes: ["192.168.253.101:9300","192.168.253.102:9300","192.168.253.103:9300"]
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
ingest.geoip.downloader.enabled: false

节点三

shell
vim config/elasticsearch.yml


cluster.name: shuofeng-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: ["192.168.253.101:9300","192.168.253.102:9300","192.168.253.103:9300"]
cluster.initial_master_nodes: ["192.168.253.101:9300","192.168.253.102:9300","192.168.253.103:9300"]
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
ingest.geoip.downloader.enabled: false

配置说明

discovery.seed_hosts 参数

解释描述
功能discovery.seed_hosts 参数用于配置集群中用于发现其他节点的主机名或 IP 地址列表。
作用每个节点通过这个参数指定其他节点的地址,以便在启动时进行发现和加入集群。
配置在每个节点的 elasticsearch.yml 配置文件中设置该参数,指定其他节点的地址,多个地址使用逗号分隔。

cluster.initial_master_nodes 参数

解释描述
功能cluster.initial_master_nodes 参数用于配置初始主节点的名称。
作用当集群启动时,用于指定初始的主节点,以启动集群的选主过程。
配置只需在初始启动的几个节点的 elasticsearch.yml 配置文件中设置该参数,列出节点名称。

注意

  • cluster.initial_master_nodes 参数和 discovery.seed_hosts 参数之间的设置应该保持一致,
  • 确保集群中的所有节点都能正确发现和加入。

启动 ElasticSearch

shell
#  切换到 es_root 用户
su es_root   # 密码: 123!@#.com

# 进入bin目录下启动
cd /usr/local/es/elasticsearch-8.4.1

# 后台启动
./elasticsearch &

常见命令

shell
#查看集群健康情况
http://192.168.253.101:9200/_cluster/health


#查看分片情况
http://192.168.253.101:9200/_cat/shards?v=true&pretty


#查看节点分布情况
http://192.168.253.101:9200/_cat/nodes?v=true&pretty


#查看索引列表
http://192.168.253.101:9200/_cat/indices?v=true&pretty

集群状态说明

状态描述
green所有的主分片和副本分片都正常运行。
yellow所有的主分片都正常运行,但有部分副本分片运行不正常。
red主分片没能正常运行