当前位置:   article > 正文

ElasticSearch高可用集群搭建_es高可用搭建

es高可用搭建

1.环境准备

本文已三个节点(服务器)为例,准备三台服务器

2.搭建过程

1).三台服务器分别搭建es (ES8+JDK17)

上传安装包和解压

tar -zxvf elasticsearch-8.4.1-linux-x86_64.tar.gz
  • 1

新建一个用户,安全考虑,elasticsearch默认不允许以root账号运行

创建用户:useradd es_user
设置密码:passwd es_user
  • 1
  • 2

修改目录权限

# 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

修改文件和进程最大打开数,需要root用户,如果系统本身有这个文件最大打开数和进程最大打开数配置,则不用

在文件内容最后添加后面两行(切记*不能省略)

vim /etc/security/limits.conf

* soft nofile 65536
* hard nofile 65536
  • 1
  • 2
  • 3
  • 4

修改虚拟内存空间,默认太小

在配置文件中改配置 最后一行上加上,执行 sysctl -p(立即生效)
vim /etc/sysctl.conf

vm.max_map_count=262144
  • 1
  • 2
  • 3
  • 4

修改elasticsearch的JVM内存,机器内存不足,常规线上推荐16到24G内存

vim config/jvm.options

-Xms1g
-Xmx1g
  • 1
  • 2
  • 3
  • 4

2).搭建集群

节点一

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

节点二

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

节点三

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

配置说明

  • 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
切换到es_user用户启动, 进入bin目录下启动, &为后台启动,再次提示es消息时 Ctrl + c 跳出

./elasticsearch &
  • 1
  • 2
  • 3

常见命令,可以用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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

集群状态说明

green:所有的主分片和副本分片都正常运行。

yellow:所有的主分片都正常运行,但有部分副本分片运行不正常。

red:主分片没能正常运行

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/844656
推荐阅读
相关标签
  

闽ICP备14008679号