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. MongoDB will only choose hidden members as a last resort. settings.chainingAllowed
设置允许辅助成员从其他辅助中同步,则MongoDB在选择同步目标时默认情况下更喜欢非隐藏成员而不是隐藏成员。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
的文档。
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
的值混淆。
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关闭时,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版本而异。