Configure a Hidden Replica Set Member配置隐藏的副本集成员

On this page本页内容

Hidden members are part of a replica set but cannot become primary and are invisible to client applications. 隐藏成员是副本集的一部分,但不能成为primary,并且对客户端应用程序不可见。Hidden members may vote in elections. 隐藏成员可以在选举中投票。For more information on hidden members and their uses, see Hidden Replica Set Members.有关隐藏成员及其使用的详细信息,请参阅隐藏副本集成员

Considerations注意事项

The most common use of hidden nodes is to support delayed members. 隐藏节点的最常见用法是支持延迟成员If you only need to prevent a member from becoming primary, configure a priority 0 member.如果只需要防止成员成为主要成员,请配置优先级为0的成员

If the settings.chainingAllowed setting allows secondary members to sync from other secondaries, MongoDB by default prefers non-hidden members over hidden members when selecting a sync target. 如果settings.chainingAllowed设置允许次要成员与其他次要成员同步,则在选择同步目标时,MongoDB默认情况下更喜欢非隐藏成员而不是隐藏成员。MongoDB will only choose hidden members as a last resort. MongoDB只能选择隐藏成员作为最后的选择。If you want a secondary to sync from a hidden member, use the replSetSyncFrom database command to override the default sync target. 如果希望从隐藏成员同步辅助对象,请使用replSetSyncFrom数据库命令覆盖默认同步目标。See the documentation for replSetSyncFrom before using the command.在使用命令之前,请参阅replSetSyncFrom的文档。

Tip提示
See also: 参阅:

Examples示例

Member Configuration Document成员配置文档

To configure a secondary member as hidden, set its members[n].priority value to 0 and set its members[n].hidden value to true in its member configuration:要将次要成员配置为隐藏,请在其成员配置中将其members[n].priority值设置为0,并将其members[n].hidden值设置为true

{
  "_id" : <num>
  "host" : <hostname:port>,
  "priority" : 0,
  "hidden" : true
}

Configuration Procedure配置程序

The following example hides the secondary member currently at the index 0 in the members array. 以下示例隐藏members数组中当前索引0处的辅助成员。To configure a hidden member, use the following sequence of operations in a mongosh session that is connected to the primary, specifying the member to configure by its array index in the members array:要配置隐藏成员,请在连接到主会话的mongosh会话中使用以下操作序列,通过members数组中的数组索引指定要配置的成员:

cfg = rs.conf()
cfg.members[0].priority = 0
cfg.members[0].hidden = true
rs.reconfig(cfg)

After re-configuring the set, this secondary member has a priority of 0 so that it cannot become primary and is hidden. 重新配置集合后,此次要成员的优先级为0,因此它不能成为主要成员并且被隐藏。The other members in the set will not advertise the hidden member in the hello command or db.hello() method output.集合中的其他成员不会在hello命令或db.hello()方法输出中公布隐藏成员。

When updating the replica configuration object, access the replica set members in the members array with the array index. 更新副本配置对象时,使用数组索引访问members数组中的副本集成员。The array index begins with 0. 数组索引以0开头。Do not confuse this index value with the value of the members[n]._id field in each document in the members array.不要将此索引值与members数组中每个文档中的members[n]._id字段的值混淆。

Warning警告
  • The rs.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 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相关文件

←  Prevent Secondary from Becoming PrimaryConfigure a Delayed Replica Set Member →