为什么我们在 MongoDB 复制中需要一个“仲裁者”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18211154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why do we need an 'arbiter' in MongoDB replication?
提问by u290629
Assume we setup a MongoDB replication without arbiter, If the primary is unavailable, the replica set will elect a secondary to be primary.So I think it's kind of implicitarbiter, since the replica will elect a primary automatically.
假设我们设置了一个没有仲裁器的 MongoDB 复制,如果主节点不可用,副本集将选择一个辅助节点作为主节点。所以我认为这是一种隐含的仲裁者,因为副本会自动选择一个主要的。
So I am wondering why do we need a dedicated arbiter node? Thanks!
所以我想知道为什么我们需要一个专用的仲裁节点?谢谢!
回答by Bruno Bronosky
I created a spreadsheetto better illustrate the effect of Arbiter nodes in a Replica Set.
我创建了一个电子表格来更好地说明副本集中仲裁节点的效果。
It basically comes down to these points:
基本上归结为以下几点:
- With an RS of 2 data nodes, losing 1 server brings you below your voting minimum (which is "greater than N/2"). An arbiter solves this.
- With an RS of even numbered data nodes, adding an Arbiter increases your fault tolerance by 1 without making it possible to have 2 voting clusters due to a split.
- With an RS of odd numbered data nodes, adding an Arbiter would allow a split to create 2 isolated clusters with "greater than N/2" votes and therefore a split brain scenario.
- 使用2 个数据节点的 RS ,失去 1 个服务器会使您低于最低投票数(“大于 N/2”)。仲裁者解决了这个问题。
- 使用偶数数据节点的 RS ,添加仲裁器将您的容错能力提高 1,而不会因为分裂而有 2 个投票集群。
- 对于奇数编号数据节点的 RS ,添加仲裁器将允许拆分创建 2 个具有“大于 N/2”选票的孤立集群,因此会出现裂脑场景。
Elections are explained [in poor] detail here. In that document it statesthat an RS can have 50 members (even number) and 7 voting members. I emphasize "states" because it does not explainhow it works. To me it seems that if you have a split happen with 4 members (all voting) on one side and 46 members (3 voting) on the other, you'd rather have the 46 elect a primary and the 4 to be a read-only cluster. But, that's exactly what "limited voting" prevents. In that situation you will actually have a 4 member cluster with a primary and a 46 member cluster that is read only. Explaining how that makes sense is out of the scope of this question and beyond my knowledge.
此处[详细] 解释了选举。在该文件中,它规定RS 可以有 50 名成员(偶数)和 7 名投票成员。我强调“状态”,因为它没有解释它是如何工作的。对我来说,如果你在一侧有 4 名成员(全部投票)而另一侧有 46 名成员(3 名投票)发生分裂,你宁愿让 46 人选举一个主要成员,而 4 个成员则是阅读-只有集群。但是,这正是“有限投票”所阻止的。在这种情况下,您实际上将拥有一个 4 成员集群,其中一个主集群和一个 46 成员集群是只读的。解释这如何有意义超出了这个问题的范围,也超出了我的知识范围。
回答by Sammaye
This really comes down to the CAP theorem whereby it is stated that if there are equal number of servers on either side of the partition the database cannot maintain CAP (Consistency, Availability, and Partition tolerance). An Arbiter is specifically designed to create an "imbalance" or majority on one side so that a primary can be elected in this case.
这实际上归结为 CAP 定理,即如果分区两侧的服务器数量相等,则数据库无法维持 CAP(一致性、可用性和分区容错性)。仲裁者专门设计用于在一侧创建“不平衡”或多数,以便在这种情况下可以选出主要成员。
If you get an even number of nodes on either side MongoDB will not elect a primary and your set will not accept writes.
如果您在任一侧获得偶数个节点,MongoDB 将不会选择主节点,并且您的集合将不接受写入。
Edit
编辑
By either side I mean, for example, 2 on one side and 2 on the other. My English wasn't easy to understand there.
我的意思是,例如,一侧有 2 个,另一侧有 2 个。我的英语在那里不容易理解。
So really what I mean is both sides.
所以我真正的意思是双方。
Edit
编辑
Wikipedia presents quite a good case for explaining CAP: http://en.wikipedia.org/wiki/CAP_theorem
维基百科提供了一个很好的解释 CAP 的案例:http: //en.wikipedia.org/wiki/CAP_theorem
回答by JERRY
Its necessary to have a arbiter in a replication for the below reasons:
由于以下原因,必须在复制中使用仲裁器:
- Replication is more reliable if it has odd number of replica sets. Incase if there is even number of replica sets its better to add a arbiter in the replication.
- Arbiters do not holddata in them and they are just to vote in election when there is any node failure.
- Arbiter is a light weight process they do not consume much hardware resources.
- Arbiters just exchange the user credentials data between the replica set which are encrypted.
- Vote during elections,hearbeats and configureation data are not encrypted while communicating in between the replica sets.
- It is better to run arbiter on a separate machine rather than along with any one of the replica set to retain high availability.
- 如果副本集数量为奇数,则复制更可靠。如果有偶数个副本集,最好在复制中添加仲裁器。
- 仲裁者不保存数据,他们只是在任何节点故障时进行选举投票。
- Arbiter 是一个轻量级的进程,它们不会消耗太多的硬件资源。
- 仲裁者只是在加密的副本集之间交换用户凭据数据。
- 选举期间的投票、心跳和配置数据在副本集之间通信时不加密。
- 最好在单独的机器上运行仲裁器,而不是与任何一个副本集一起运行以保持高可用性。
Hope this helps !!!
希望这可以帮助 !!!
回答by Adil
Arbiters are an optionalmechanism to allow voting to succeed when you have an even number of mongods deployed in a replicaset. Arbiters are light weight, meant to be deployed on a server that is NOT a dedicated mongo replica, i.e: the server's primary role is some other task, like a redis server. Since they're light they won't interfere (noticeably) with the system's resources.
仲裁器是一种可选机制,当您在副本集中部署偶数个 mongod 时,允许投票成功。仲裁器是轻量级的,旨在部署在不是专用 mongo 副本的服务器上,即:服务器的主要角色是一些其他任务,如 redis 服务器。由于它们很轻,因此不会(明显地)干扰系统资源。
From the docs :
从文档:
An arbiter does not have a copy of data set and cannot become a primary. Replica sets may have arbiters to add a vote in elections of for primary. Arbiters allow replica sets to have an uneven number of members, without the overhead of a member that replicates data.
仲裁者没有数据集的副本,也不能成为主要的。副本集可能有仲裁者在主选举中添加投票。仲裁器允许副本集具有奇数个成员,而无需成员复制数据的开销。