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. 要将成员配置为无投票,请使用replSetReconfig命令或其mongosh助手方法rs.reconfig()将其members[n].votesmembers[n].priority值设置为0Non-voting replica set members must have a priority of 0.非投票副本集成员的priority必须为0

Note注意

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. 要修改多个成员的投票,请执行一系列replSetReconfigrs.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 replSetStepDown or its shell helper rs.stepDown() before performing this procedure.要将primary成员转换为无投票成员,必须首先使用replSetStepDown或其shell助手rs.stepDown()成功地将主要成员降级,然后才能执行此过程。

1) Connect to the Replica Set Primary连接到主副本集

Connect mongosh to 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. <hostname><port>替换为副本集主副本的主机名和端口。Include any other parameters required for your deployment.包括部署所需的任何其他参数。

2) Retrieve the Replica Configuration检索副本配置

Issue the rs.conf() method in the shell and assign the result to a variable cfg:在shell中发出rs.conf()方法,并将结果分配给变量cfg

cfg = rs.conf();

The returned document contains a members array, 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 votes and priority to 0.要将副本成员更改为无投票,请将其votespriority设置为0

cfg.members[n].votes = 0;
cfg.members[n].priority = 0;

Replace n with the array index position of the member to modify. n替换为要修改的成员的数组索引位置。The members array is zero-indexed, where the first element in the array has an index position of 0.members数组为零索引,其中数组中的第一个元素的索引位置为0。

The array index position of a member in the members array is distinct from the members[n]._id of a specific member. 成员数组中members数组索引位置不同于特定成员的members[n]._idDo not use the _id to reference the array index position of any any member in members.不要使用_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);
Warning警告
  • The rs.reconfig() shell method can force the current primary to step down, which causes an election. rs.reconfig()shell方法可以强制当前的初选下台,从而导致选举When the primary steps down, the mongod closes all client connections. 当主服务器关闭时,mongod关闭所有客户端连接。While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods.虽然这通常需要10-20秒,但请尝试在计划维护期间进行这些更改。
  • Avoid reconfiguring replica sets that contain members of different MongoDB versions as validation rules may differ across MongoDB versions.避免重新配置包含不同MongoDB版本成员的副本集,因为验证规则可能会因MongoDB版本而异。

Related Documents相关文件

←  Configure a Delayed Replica Set Member配置延迟副本集成员Convert a Secondary to an Arbiter将辅助转换为仲裁器 →