当master宕机时zookeeper是怎么做的 [英] how does zookeeper do when the master down

查看:30
本文介绍了当master宕机时zookeeper是怎么做的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题可能看起来很傻,但我真的无法理解当master宕机时zookeeper的故障转移策略,尽管我阅读了很多关于Zookeeper的文档.我的问题如下:

The title may look like silly, but I really can't understand the zookeeper failover policy when the master is down although I read a lot of docs about Zookeeper. My question as following:

  1. 如果我有3个节点zookeeper,那么master宕机了,那怎么办剩下的两个节点选举新的主节点(现在是偶数编号节点,它们如何通过多数投票).
  2. 如果剩下的一个两个节点宕机,那么最后一个将成为主节点并不断请提供服务,好吗?
  3. 如果偶数个zookeeper节点可以运行得很好,为什么我要设置奇数个Zookeeper节点?

推荐答案

  1. 我认为你误解了我们在这里谈论的多数.重要的大多数不在剩余节点中,而是在整个集群中.所以你需要问的是:2个节点可以在3个节点中占多数吗"?答案是他们可以,因此他们可以选举一个领导者.(我不知道 Zookeeper 是如何解决领导者投票的,但重要的是节点的目标不是成为领导者,而是决定一个领导者.并且让你信服,这里有一种简单(但缓慢)的方式解决方法:节点随机投票,如果他们已经形成多数,他们会选举那个领导者,否则他们再次投票.)

  1. I think you're misunderstanding what majority we're talking about here. The majority that is important is not among the remaining nodes, but among the entire cluster. So what you need to ask is: 'Can 2 nodes form a majority among 3 nodes'? And the answer is that they can, and therefore they can elect a leader. (I do not know exactly how Zookeeper solves leader voting, but the important thing is that the goals for the nodes is not to become leader but to decide on one leader. And to convince you it's possible here's a vary simple (but slow) way of solving it: The nodes vote at random, if they have formed a majority they elect that leader else they vote again.)

不,情况并非如此.由于集群仍然配置为 3 节点集群,因此剩下的一个节点不能形成多数,因此不能选举领导者.这就是为什么 2 节点集群实际上可能比 1 节点集群更糟糕的原因之一,如果其中一个节点出现故障,集群就会停止.

No, this will not be the case. Since the cluster is still configured around being a 3 node cluster the one node that is left can not form a majority and can therefor not elect a leader. This is one of the reasons why a 2 node cluster can actually be worse then a 1 node one, if one of the nodes go down the cluster stops.

您不必这样做,只是建议.有一个奇数的一个很好的理由是,如果你得到一个网络分割,将你的集群分成相同大小的两个部分,没有一方可以选举领导者.(如果您运行奇数个节点,这是不可能的.)您也可以将其视为买一送一的交易类型,如果您有 4 个节点,则只有 1 个可以关闭,但如果您有 5 个节点,则可以关闭 2 个.但是如果你有 6 个节点,那么它仍然只有 2 个节点可以在集群不宕机的情况下宕机.

You do not have to, it is just recommended. And a good reason to have a odd number is that if you get a net-split that divides your cluster into two parts of same size no side can elect a leader. (This is not possible if you run a odd number of nodes.) You can also see it as a buy-one-get-one-free type of deal, if you have 4 nodes only 1 can go down, but if you get 5 nodes it's okay for 2 to go down. But if you get 6 nodes it's still just 2 nodes that can go down without the cluster going down.

这篇关于当master宕机时zookeeper是怎么做的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆