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 | 主分片没能正常运行 |
朔风