配置一个不参与投票的节点¶
On this page
如果可能的话,每个节点都应该拥有一票选举票。这样可以防止选举僵局,死锁或是避免不当的节点成为主节点。通过 priority 参数来设置各个节点成为主节点的优先级。
例子¶
To disable the ability to vote in elections for the fourth, fifth, and sixth replica set members, use the following command sequence in the mongo shell connected to the primary. You identify each replica set member by its array index in the members array:
cfg = rs.conf()
cfg.members[3].votes = 0
cfg.members[4].votes = 0
cfg.members[5].votes = 0
rs.reconfig(cfg)
This sequence gives 0 votes to the fourth, fifth, and sixth members of the set according to the order of the members array in the output of rs.conf(). This setting allows the set to elect these members as primary but does not allow them to vote in elections. Place voting members so that your designated primary or primaries can reach a majority of votes in the event of a network partition.
When updating the replica configuration object, access the replica set members in the members array with the array index. The array index begins with 0. Do not confuse this index value with the value of the members[n]._id field in each document in the members array.
警告
- The rs.reconfig() shell method can force the current primary to step down, which causes an election. When the primary steps down, the mongod closes all client connections. While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods.
为了能让复制集的配置修改成功应用,我们需要确保复制集的多数节点是可用的。如果我们的复制集是由偶数个节点组成的,那就需要新增一个 arbiter 来确保选举的正常进行。
In general and when possible, all members should have only 1 vote. This prevents intermittent ties, deadlocks, or the wrong members from becoming primary. Use members[n].priority to control which members are more likely to become primary.