Configure Non-Voting Replica Set Member配置无表决权副本集成员
On this page本页内容
Non-voting members allow you to add additional members for read distribution beyond the maximum seven voting members.无投票权成员允许您在最多七个投票权成员之外添加其他成员进行阅读分发。
To configure a member as non-voting, use the 要将成员配置为无投票权,请使replSetReconfig command or its mongosh helper method rs.reconfig() to set its members[n].votes and members[n].priority values to 0. Non-voting replica set members must have a priority of 0.replSetReconfig命令或其mongosh助手方法rs.reconfig()将其members[n].votes和members[n].priority值设置为0。无表决权的副本集成员的priority必须为0。
Starting in MongoDB 4.4, replica reconfiguration can add or remove no more than one voting replica set member at a time. 从MongoDB 4.4开始,副本重新配置可以一次添加或删除不超过一个投票副本集成员。To modify the votes of multiple members, issue a series of 要修改多个成员的投票,请执行一系列replSetReconfig or rs.reconfig() operations to modify one member at a time. replSetReconfig或rs.reconfig()>操作,一次修改一个成员。See Reconfiguration Can Add or Remove No More than One Voting Member at a Time for more information.有关详细信息,请参阅重新配置一次最多可添加或删除一个投票成员。
Procedure过程
The following procedure converts configures a single secondary replica set member to be non-voting. 以下过程将单个secondary副本集成员配置为无表决权。To convert the primary member to be non-voting, you must first successfully step the primary down using 若要将primary成员转换为无投票权成员,必须首先使用replSetStepDown or its shell helper rs.stepDown() before performing this procedure.replSetStepDown或其shell助手rs.stepDown()成功地逐步减少主要成员,然后才能执行此过程。
- 1)
Connect to the Replica Set Primary连接到复制副本集主 -
Connect将mongoshto the replica set primary:mongosh连接到复制副本集primary:mongosh --host "<hostname>:<port>"Replace the将<hostname>and<port>with the hostname and port of the replica set primary. Include any other parameters required for your deployment.<hostname>和<port>替换为复制副本集主服务器的主机名和端口。包括部署所需的任何其他参数。 - 2)
Retrieve the Replica Configuration检索副本配置 -
Issue the在shell中发出rs.conf()method in the shell and assign the result to a variablecfg:rs.conf()方法,并将结果分配给变量cfg:cfg = rs.conf();The returned document contains a返回的文档包含一个membersarray, where each element in the array contains the configuration for a single replica set member.members数组,其中数组中的每个元素都包含单个副本集成员的配置。 - 3)
Configure the Member to be Non-Voting将成员配置为无表决权 -
For the replica member to change to be non-voting, set its若要将副本成员更改为无表决权成员,请将其votesandpriorityto0.votes和priority设置为0。cfg.members[n].votes = 0;
cfg.members[n].priority = 0;Replace将nwith the array index position of the member to modify.n替换为要修改的成员的数组索引位置。Themembersarray is zero-indexed, where the first element in the array has an index position of0.members数组为零索引,其中数组中的第一个元素的索引位置为0。The array index position of a member in themembersarray is distinct from themembers[n]._idof a specific member.members数组中成员的数组索引位置不同于特定成员的members[n]._id。Do not use the不要使用_idto reference the array index position of any any member inmembers._id引用members中任何成员的数组索引位置。 - 4)
Reconfigure the Replica Set with the New Configuration使用新配置重新配置副本集 -
Use使用rs.reconfig()method to reconfigure the replica set with the updated replica set configuration document.rs.reconfig()方法使用更新的副本集配置文档重新配置副本集。rs.reconfig(cfg);
Thers.reconfig()shell method can force the current primary to step down, which causes an election.rs.reconfig()shell方法可以强制当前的primary退出,从而导致选举。When the primary steps down, the当primary关闭时,mongodcloses all client connections. While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods.mongod会关闭所有客户端连接。虽然这通常需要10-20秒,但请尝试在计划维护期间进行这些更改。Avoid reconfiguring replica sets that contain members of different MongoDB versions as validation rules may differ across MongoDB versions.避免重新配置包含不同MongoDB版本成员的副本集,因为验证规则可能因MongoDB版本而异。