discovery.zen.minimum_master_nodes深度解析

本文深入探讨了Elasticsearch集群中discovery.zen.minimum_master_nodes参数的重要性,此参数确保集群在面对网络分区时能有效防止脑裂现象,保护数据一致性。通过详细解析quorum算法及其应用场景,帮助读者理解如何正确配置此参数以增强集群稳定性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

discovery.zen.minimum_master_nodes对集群的稳定性至关重要,防止脑裂的出现。

脑裂:

如果网络的故障导致一个集群被划分成两片,每片都有多个node,以及一个master。因为master是维护集群状态,以及shard的分配。如果出现了两个master,可能导致数据破损。

discovery.zen.minimum_master_nodes的作用是只有足够的master候选节点时,才可以选举出一个master。该参数必须设置为集群中master候选节点的quorum数量。

quorum的算法=master候选节点数量/2+1

举例:

1、如果有10个节点,都是data node,也是master的候选节点。则quorum=10/2+1=6

2、如果有3个master候选节点,100个数据节点。则quorum=3/2+1=2

3、如果有2个节点,都是data node,也是master的候选节点。则quorum=2/2+1=2(有问题)

如果其中一个节点挂了,那么master的候选节点只有一个,无法满足quorum数量。即无法选举出master。此时只能将quorum设置成1,但是设置为1有可能出现脑裂。

总结:一般es集群的节点至少要有3个,quorum设置为2

使用例2的场景说明quorum是如何防止脑裂

假设集群中3个节点有一个节点与其他节点无法通信,

1、如果master是单独的节点,另外2个节点是master候选节点。那么此时单独的master节点因为没有指定数量的候选master node在自己当前所在的集群里。因此会取消当前的master角色,尝试重新选举(无法选举成功)

另外一个网络区域内的node因为无法连接到master,就会发起重新选举,有两个候选节点,满足quorum,成功选举出一个master。

2、如果master和一个node在一个网络区域(A),另一个node单独在一个网络区域(B)。

B区域只有一个node,因为连不上master,会尝试发起选举,但不满足quorum,无法选举

A区域master继续工作,当前网络也满足quorum,不发起选举。

 

discovery.zen.minimum_master_nodes除了在配置文件设置,也可以动态设置

PUT /_cluster/settings
{
   "persistent":{
      "discovery.zen.minimum_master_nodes":2
   }
}

# ======================== Elasticsearch Configuration ========================= # # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # # Please consult the documentation for further information on configuration options: # https://www.elastic.co/guide/en/elasticsearch/reference/index.html # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: MyES # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: node.name: master node.master: true node.data: true # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # path.data: /var/lib/elasticsearch # # Path to log files: # path.logs: /var/log/elasticsearch # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # bootstrap.memory_lock: false bootstrap.system_call_filter: false # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # network.host: 192.168.100.130 # # Set a custom port for HTTP: # http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" # # For more information, consult the network module documentation. # # --------------------------------- Discovery ---------------------------------- # # Pass an initial list of hosts to perform discovery when new node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # #discovery.zen.ping.unicast.hosts: ["host1", "host2"] discovery.zen.ping.unicast.hosts: ["192.168.100.130", "192.168.100.131","192.168.100.132"] # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1): discovery.zen.minimum_master_nodes: 3 #discovery.zen.minimum_master_nodes: # # For more information, consult the zen discovery module documentation. # # ---------------------------------- Gateway ----------------------------------- # # Block initial recovery after a full cluster restart until N nodes are started: # #gateway.recover_after_nodes: 3 # # For more information, consult the gateway module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true 这是我的master里的配置,请帮我配置slave1和slave2
最新发布
05-23
### 配置 Elasticsearch 集群中的 Slave1 和 Slave2 节点 在配置 Elasticsearch 集群时,Slave 节点主要用于处理数据存储和查询请求。以下是基于已有 Master 节点配置的情况下,如何设置 Slave1 和 Slave2 节点的详细说明。 #### 1. **基本配置项解释** - **`cluster.name`**: 确保所有节点属于同一个集群,因此需要与 Master 节点保持一致。 - **`node.name`**: 每个节点都需拥有唯一的名称,以便区分不同节点的功能。 - **`node.master`**: 设置为 `false` 表明该节点不会参与主节点选举过程[^3]。 - **`node.data`**: 设定为 `true`,表明此节点能够承担实际的数据存储功能[^2]。 - **`network.host`**: 定义当前节点监听的网络地址,通常设为本机 IP 地址或特定网卡地址。 - **`discovery.seed_hosts` / `cluster.initial_master_nodes`**: 声明哪些主机可以作为潜在的 Master 节点,确保新加入的节点能找到集群中的 Master[^1]。 #### 2. **具体配置示例** 对于 Slave1 和 Slave2 的配置文件(通常是 `/etc/elasticsearch/elasticsearch.yml`),可以根据以下模板进行编辑: ##### **Slave1 配置** ```yaml # 集群名称,必须与 Master 节点相同 cluster.name: your_cluster_name # 当前节点名称,唯一标识符 node.name: slave1 # 不允许竞选为主节点 node.master: false # 允许存储数据 node.data: true # 绑定到本地或其他指定IP地址 network.host: 192.168.x.x # 替换为实际IP地址 # HTTP服务端口,默认即可 http.port: 9200 # Transport协议端口,默认即可 transport.tcp.port: 9300 # 发现机制中列出已知的Master节点 discovery.seed_hosts: ["master_node_ip", "another_master_node_ip"] # 初始主节点列表 cluster.initial_master_nodes: ["master_node_name", "another_master_node_name"] ``` ##### **Slave2 配置** 除了更改 `node.name` 外,其余部分几乎完全一样: ```yaml # 集群名称,必须与 Master 节点相同 cluster.name: your_cluster_name # 当前节点名称,唯一标识符 node.name: slave2 # 不允许竞选为主节点 node.master: false # 允许存储数据 node.data: true # 绑定到本地或其他指定IP地址 network.host: 192.168.y.y # 替换为实际IP地址 # HTTP服务端口,默认即可 http.port: 9200 # Transport协议端口,默认即可 transport.tcp.port: 9300 # 发现机制中列出已知的Master节点 discovery.seed_hosts: ["master_node_ip", "another_master_node_ip"] # 初始主节点列表 cluster.initial_master_nodes: ["master_node_name", "another_master_node_name"] ``` #### 3. **启动前准备事项** - **内存映射调整**:为了避免 JVM 报错,建议预先提升系统的最大内存映射数量。可以通过命令行临时修改或永久生效的方式完成此项工作: ```bash sysctl -w vm.max_map_count=262144 ``` - **Docker 网络环境**:如果是在 Docker 下运行,则需要提前创建好容器间的共享网络环境[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值