Replace a Replica Set Member替换副本集成员

On this page本页内容

If you need to change the hostname of a replica set member without changing the configuration of that member or the set, you can use the operation outlined in this tutorial. 如果需要更改副本集成员的主机名而不更改该成员或集的配置,则可以使用本教程中概述的操作。For example if you must re-provision systems or rename hosts, you can use this pattern to minimize the scope of that change.例如,如果必须重新配置系统或重命名主机,则可以使用此模式来最小化更改的范围。

Operation操作

To change the hostname for a replica set member modify the members[n].host field. 要更改副本集成员的主机名,请修改members[n].host字段。The value of members[n]._id field will not change when you reconfigure the set.重新配置集合时,members[n]._id字段的值不会更改。

See Replica Set Configuration and rs.reconfig() for more information.有关详细信息,请参阅副本集配置rs.reconfig()

Note注意

Any replica set configuration change can trigger the current primary to step down, which forces an election. 任何副本集配置更改都会触发当前primary降级,从而强制进行选举During the election, the current shell session and clients connected to this replica set disconnect, which produces an error even when the operation succeeds.在选择期间,当前shell会话和连接到此副本集的客户端断开连接,即使操作成功,也会产生错误。

Example示例

To change the hostname to mongo2.example.net for the replica set member configured at members[0], issue the following sequence of commands:要将在members[0]处配置的副本集成员的主机名更改为mongo2.example.net,请发出以下命令序列:

cfg = rs.conf()
cfg.members[0].host = "mongo2.example.net"
rs.reconfig(cfg)
←  Remove Members from Replica SetMember Configuration Tutorials →