ES elasticsearch集群配置

1 环境准备

1.1 服务器资源

这里我使用的是虚拟机环境

服务器 IP地址
node1 192.168.51.4
node2 192.168.51.5
node3 192.168.51.6

1.2 安装和配置es

详情可参照博文: https://blog.csdn.net/qq_15769939/article/details/114249211

如果是虚拟机环境的话,可以直接部署一台,克隆两台。

如果是克隆的话,需要将自定义的es data目录的数据全部清空,按照我的教程来安装的话,需要清空

/usr/local/elasticsearch-7.4.2/data 目录下的所有文件

2 配置集群

2.1 node1

编辑配置文件

[root@localhost config]# vi /usr/local/elasticsearch-7.4.2/config/elasticsearch.yml

配置文件需修改的内容

# 配置集群名称,保证每个节点的名称相同,确保处于一个集群之内
cluster.name: auskat-es-cluster

# 节点名称,每个节点都不同
node.name: es-node1

# http端口 (默认端口)
http.port: 9200

# 主节点,作用主要是用来管理整个集群,负责创建或删除索引,管理其他非master节点(leader)
node.master: true

# 数据节点,用于对文档数据的增删改查
node.data: true

# 集群列表
discovery.seed_hosts: ["192.168.51.4","192.168.51.5","192.168.51.6"]


# 启动的时候使用一个master节点
cluster.initial_master_nodes: ["es-node1]

命令去除注释,查看配置文件信息

[root@localhost config]# more /usr/local/elasticsearch-7.4.2/config/elasticsearch.yml | grep ^[^#]

2.2 node2

编辑配置文件

[root@localhost config]# vi /usr/local/elasticsearch-7.4.2/config/elasticsearch.yml

配置文件需修改的内容

# 配置集群名称,保证每个节点的名称相同,确保处于一个集群之内
cluster.name: auskat-es-cluster

# 节点名称,每个节点都不同
node.name: es-node2

# http端口 (默认端口)
http.port: 9200

# 主节点,作用主要是用来管理整个集群,负责创建或删除索引,管理其他非master节点(leader)
node.master: true

# 数据节点,用于对文档数据的增删改查
node.data: true

# 集群列表
discovery.seed_hosts: ["192.168.51.4","192.168.51.5","192.168.51.6"]


# 启动的时候使用一个master节点
cluster.initial_master_nodes: ["es-node1]

命令去除注释,查看配置文件信息

[root@localhost config]# more /usr/local/elasticsearch-7.4.2/config/elasticsearch.yml | grep ^[^#]

2.3 node3

编辑配置文件

[root@localhost config]# vi /usr/local/elasticsearch-7.4.2/config/elasticsearch.yml

配置文件需修改的内容

# 配置集群名称,保证每个节点的名称相同,确保处于一个集群之内
cluster.name: auskat-es-cluster

# 节点名称,每个节点都不同
node.name: es-node3

# http端口 (默认端口)
http.port: 9200

# 主节点,作用主要是用来管理整个集群,负责创建或删除索引,管理其他非master节点(leader)
node.master: true

# 数据节点,用于对文档数据的增删改查
node.data: true

# 集群列表
discovery.seed_hosts: ["192.168.51.4","192.168.51.5","192.168.51.6"]


# 启动的时候使用一个master节点
cluster.initial_master_nodes: ["es-node1]

命令去除注释,查看配置文件信息

[root@localhost config]# more /usr/local/elasticsearch-7.4.2/config/elasticsearch.yml | grep ^[^#]

2.4 启动服务

分别启动三点节点的elasticsearch服务

[root@localhost config]# cd /usr/local/elasticsearch-7.4.2/bin
[root@localhost bin]# ./elasticsearch -d

3 集群脑裂问题

3.1 介绍

如果发生网络中断或者服务器宕机,那么集群就有可能被划分为两个部分,每个部分都有自己的master来管理,这个就是脑裂。

3.2 解决方案

master主节点要经过多个master节点共同选举后才能成为新的主节点。

ES7 以下解决方案

  • 半数以上的节点统一选举,节点方才可以成为新的master
  • discovery.zen.minimun_master_nodes = (N/2) + 1
  • N为集群中的master节点的数量,也就是 node.master=true 设置的服务器节点的总数

ES 7.X

在最新版的7.X版本中,minimun_master_nodes 这个参数已经被移除,换做有es自身去管理,这样就避免了脑裂的问题,选举速度会比较快。

4 相关信息

  • 博文不易,辛苦各位猿友点个关注和赞,感谢

猜你喜欢

转载自blog.csdn.net/qq_15769939/article/details/114915207