模块modules-Discovery

Discovery and cluster formation

How nodes discover each other, elect a master and form a cluster. 节点发现 选举master

Discovery 发现

Discovery is the process where nodes find each other when the master is unknown, such as when a node has just started up or when the previous master has failed.

集群发现

配置两种

 seed hosts providers to configure the list of seed nodes: a settings-based and a file-based seed hosts provider.

1) settings-based

org.elasticsearch.discovery.SettingsBasedSeedHostsProvider类解析

discovery.seed_hosts:
   - 192.168.1.10:9300
   - 192.168.1.11 
   - seeds.mydomain.com 

2) file-based

解析类 org.elasticsearch.discovery.FileBasedSeedHostsProvider

elasticsearch.yml
discovery.seed_providers: file

配置文件所在位置:$ES_PATH_CONF/unicast_hosts.txt

10.10.10.5
10.10.10.6:9305
10.10.10.5:10005
# an IPv6 address
[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:9301

可以扩充其他的插件提供支持

如 EC2 discovery plugin 

Quorum-based decision making 多数选举

This section describes how Elasticsearch uses a quorum-based voting mechanism to make decisions even if some nodes are unavailable.

新版的协议 类似于raft

Voting configurations

类 org.elasticsearch.cluster.coordination.CoordinationMetaData.VotingConfiguration

This section describes the concept of voting configurations, which Elasticsearch automatically updates as nodes leave and join the cluster.

每个Elasticsearch集群都有一个投票配置,这是一组符合主机条件的节点,在做出决策(如选择新的主机或提交新的集群状态)时,会对这些节点的响应进行计数。只有在投票配置中的大多数(超过一半)节点做出响应后,才能做出决策。

通常,投票配置与集群中当前所有符合主条件的节点的集合相同。然而,在某些情况下,它们可能会有所不同。

在节点离开集群后自动从投票配置中删除节点并不是那么简单。不同的策略有不同的优点和缺点,因此正确的选择取决于如何使用集群。您可以使用cluster.auto_shrink_voting_configuration设置来控制投票配置是否自动收缩。

当一个全新的集群首次启动时,它必须选择它的第一个主节点。要进行此选举,它需要知道其投票应该计数的主合格节点集。这个初始投票配置被称为引导配置,并在集群引导过程中设置

集群中通常应该有奇数个符合主条件的节点。如果有偶数,Elasticsearch会将其中一个排除在投票配置之外,以确保其大小为奇数。这一遗漏不会降低集群的容错能力。事实上,它稍微改进了一下:如果集群受到网络分区的影响,将其分为大小相等的两半,那么其中一半将包含大多数投票配置,并且能够继续运行。如果来自主合格节点的所有投票都被计算在内,那么双方都不会包含严格多数的节点,因此集群将无法取得任何进展

当一个全新的集群首次启动时,它必须选择它的第一个主节点。要进行此选举,它需要知道其投票应该计数的主合格节点集。这个初始投票配置被称为引导配置,并在集群引导过程中设置。

引导配置准确地确定哪些节点应该在第一次选举中投票,这一点很重要。仅仅为每个节点配置集群中应该有多少节点是不够的。同样重要的是要注意,引导配置必须来自集群外部:集群没有安全的方法来自行正确确定引导配置。

如果引导配置设置不正确,当您启动一个全新的集群时,可能会意外地形成两个单独的集群,而不是一个。这种情况可能会导致数据丢失:您可能会在注意到出现任何问题之前就开始使用这两个集群,并且以后不可能将它们合并在一起。

Bootstrapping a cluster

首次启动的集群引导  主要配置 master-ineligible nodes

通过  cluster.initial_master_nodes 配置

Bootstrapping a cluster is required when an Elasticsearch cluster starts up for the very first time. In development mode, with no discovery settings configured, this is automatically performed by the nodes themselves. As this auto-bootstrapping is inherently unsafe, running a node in production mode requires bootstrapping to be explicitly configured via the cluster.initial_master_nodes setting.

cluster.initial_master_nodes:
  - master-a
  - master-b
  - master-c

$ bin/elasticsearch -Ecluster.initial_master_nodes=master-a,master-b,master-c

Adding and removing master-eligible nodes

It is recommended to have a small and fixed number of master-eligible nodes in a cluster, and to scale the cluster up and down by adding and removing master-ineligible nodes only. However there are situations in which it may be desirable to add or remove some master-eligible nodes to or from a cluster. This section describes the process for adding or removing master-eligible nodes, including the extra steps that need to be performed when removing more than half of the master-eligible nodes at the same time.

add 

如果您希望将一些节点添加到集群中,只需配置新节点即可找到现有集群并启动它们。如果合适的话,Elasticsearch会将新节点添加到投票配置中。

在主选择期间或加入现有的已形成集群时,节点向主节点发送加入请求,以便正式添加到集群中。您可以使用cluster.join.timeout设置来配置节点在发送加入集群的请求后等待的时间。其默认值为30s。请参阅发现和集群形成设置。

removing

删除符合主条件的节点时,重要的是不要同时删除太多节点。例如,如果当前有七个符合主条件的节点,并且您希望将其减少到三个,那么不可能简单地同时停止其中四个节点:这样做将只剩下三个节点,这还不到投票配置的一半,这意味着集群无法采取任何进一步的操作。

更确切地说,如果同时关闭一半或更多符合主条件的节点,那么集群通常将不可用。如果发生这种情况,则可以通过再次启动已删除的节点来使集群重新联机

Publishing the cluster state

Cluster state publishing is the process by which the elected master node updates the cluster state on all the other nodes in the cluster.

主节点是集群中唯一可以更改集群状态的节点。主节点一次处理一批集群状态更新,计算所需的更改,并将更新后的集群状态发布给集群中的所有其他节点。每次发布都从主节点向集群中的所有节点广播更新后的集群状态开始。每个节点以确认进行响应,但尚未应用新接收的状态。一旦主机已经从足够多的符合主机条件的节点收集到确认,则称新的集群状态已提交,并且主机广播另一消息,指示节点应用现在提交的状态。每个节点接收此消息,应用更新后的状态,然后将第二个确认发送回主节点。

master允许在有限的时间内将每个集群状态更新完全发布到所有节点。它由cluster.publish.timeout设置定义,默认值为30s,从发布开始算起。如果在提交新的集群状态之前达到这个时间,那么集群状态更改将被拒绝,并且主机认为自己失败了。它停下来,开始试图选出一位新的master。

如果在cluster.publish.timeout结束之前提交了新的集群状态,则主节点认为更改已成功。它等待,直到超时结束,或者直到它收到集群中每个节点都应用了更新状态的确认,然后开始处理和发布下一个集群状态更新。如果还没有接收到一些确认(即,一些节点还没有确认它们已经应用了当前更新),则这些节点被认为是滞后的,因为它们的集群状态已经落后于主节点的最新状态。主节点等待滞后节点再赶上一段时间,cluster.follower_lag.timeout,默认为90s。如果某个节点在此时间内仍未成功应用集群状态更新,则认为该节点已失败,并将其从集群中删除。

集群状态更新通常以与以前集群状态不同的方式发布,这减少了发布集群状态更新所需的时间和网络带宽。例如,当仅更新集群状态中索引的子集的映射时,只要这些节点具有先前的集群状态,则仅需要将这些索引的更新发布到集群中的节点。如果某个节点缺少以前的群集状态,例如在重新加入群集时,主节点会将完整的群集状态发布给该节点,以便它可以接收将来的diff更新。

Elasticsearch是一种基于对等的系统,其中节点之间直接通信。高吞吐量API(索引、删除、搜索)通常不会与主节点进行交互。主节点的职责是维护全局集群状态,并在节点加入或离开集群时重新分配碎片。每次更改集群状态时,都会将新状态发布到集群中的所有节点,如上所述。

Cluster fault detection

Elasticsearch performs health checks to detect and remove faulty nodes.

Settings

There are settings that enable users to influence the discovery, cluster formation, master election and fault detection processes.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值