On this page本页内容
The following procedure applies to 5.0 config servers. 以下过程适用于5.0配置服务器。For earlier versions of MongoDB, refer to the corresponding version of the MongoDB Manual.有关MongoDB的早期版本,请参阅相应版本的MongoDB手册。
If the config server replica set becomes read only, i.e. does not have a primary, the sharded cluster cannot support operations that change the cluster metadata, such as chunk splits and migrations. 如果配置服务器副本集变为只读,即没有主副本集,则分片集群无法支持更改集群元数据的操作,例如区块分割和迁移。Although no chunks can be split or migrated, applications will be able to write data to the sharded cluster.尽管没有块可以分割或迁移,但应用程序将能够将数据写入分片集群。
If one of the config servers is unavailable or inoperable, repair or replace it as soon as possible. 如果其中一个配置服务器不可用或不可用,请尽快修复或更换。The following procedure replaces a member of a config server replica set with a new member.以下过程使用新成员替换配置服务器副本集的成员。
The tutorial is specific to MongoDB 5.0. 本教程专用于MongoDB 5.0。For earlier versions of MongoDB, refer to the corresponding version of the MongoDB Manual.有关MongoDB的早期版本,请参阅相应版本的MongoDB手册。
The following restrictions apply to a replica set configuration when used for config servers:以下限制适用于用于配置服务器的副本集配置:
members[n].buildIndexes
setting set to false).members[n].buildIndexes
设置为false
)。Start a 启动一个mongod
instance, specifying the --configsvr
, --replSet
, --bind_ip
options, and other options as appropriate to your deployment.mongod
实例,根据您的部署指定--configsvr
、--replSet
、--bind_ip
选项和其他选项。
Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. 在绑定到非本地主机(例如,可公开访问的)IP地址之前,请确保已保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整列表,请参阅安全检查表。At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证和加强网络基础设施。
mongod --configsvr --replSet <replicaSetName> --bind_ip localhost,<hostname(s)|ip address(es)>
Connect 将mongosh
to the primary of the config server replica set and use rs.add()
to add the new member.mongosh
连接到配置服务器副本集的主副本集,并使用rs.add()
添加新成员。
Before MongoDB 5.0, a newly added secondary still counts as a voting member even though it can neither serve reads nor become primary until its data is consistent. 在MongoDB 5.0之前,新添加的辅助服务器仍然算作投票成员,即使在数据一致之前,它既不能提供读操作,也不能成为主服务器。If you are running a MongoDB version earlier than 5.0 and add a secondary with its 如果您运行的MongoDB版本早于5.0,并且添加了一个votes
and priority
settings greater than zero, this can lead to a case where a majority of the voting members are online but no primary can be elected. votes
和priority
设置大于零的二级数据库,则可能会导致大多数投票成员在线,但无法选择一级数据库。To avoid such situations, consider adding the new secondary initially with 为避免出现这种情况,请考虑在开始时添加新的次要级别,priority :0
and votes :0
. priority :0
,votes :0
。Then, run 然后,运行rs.status()
to ensure the member has transitioned into SECONDARY
state. rs.status()
以确保成员已转换为SECONDARY
状态。Finally, use 最后,使用rs.reconfig()
to update its priority and votes.rs.reconfig()
更新其优先级和投票。
rs.add( { host: "<hostnameNew>:<portNew>", priority: 0, votes: 0 } )
The initial sync process copies all the data from one member of the config server replica set to the new member without restarting.初始同步进程将所有数据从配置服务器副本集的一个成员复制到新成员,而无需重新启动。
mongos
instances automatically recognize the change in the config server replica set members without restarting.实例自动识别配置服务器副本集成员中的更改,而无需重新启动。
Ensure that the new member has reached 确保新成员已达到SECONDARY
state. SECONDARY
状态。To check the state of the replica set members, run 要检查副本集成员的状态,请运行rs.status()
:rs.status()
:
rs.status()
Reconfigure the replica set to update the votes and priority of the new member:重新配置副本集以更新新成员的投票和优先级:
var cfg = rs.conf(); cfg.members[n].priority = 1; // Substitute the correct array index for the new member cfg.members[n].votes = 1; // Substitute the correct array index for the new member rs.reconfig(cfg)
where 其中n
is the array index of the new member in the members
array.n
是members
数组中新成员的数组索引。
rs.reconfig()
shell method can force the current primary to step down, which causes an election. rs.reconfig()
shell方法可以强制当前主节点下移,从而导致选举。mongod
closes all client connections. mongod
将关闭所有客户端连接。Upon completion of initial sync of the replacement config server, from a 在完成替换配置服务器的初始同步后,从连接到主服务器的mongosh
session that is connected to the primary, use rs.remove()
to remove the old member.mongosh
会话中,使用rs.remove()
删除旧成员。
rs.remove("<hostnameOld>:<portOld>")
mongos
instances automatically recognize the change in the config server replica set members without restarting.实例自动识别配置服务器副本集成员中的更改,而无需重新启动。
mongos
configuration or DNS entry.mongos
配置或DNS条目。With replica set config servers, the 对于副本集配置服务器,mongos
instances specify in the --configdb
or sharding.configDB
setting the config server replica set name and at least one of the replica set members.mongos
实例在--configdb
或sharding.configDB
设置中指定配置服务器副本集名称和至少一个副本集成员。
As such, if the 因此,如果mongos
instance does not specify the removed replica set member in the --configdb
or sharding.configDB
setting, no further action is necessary.mongos
实例没有在--configdb
或sharding.configDB
设置中指定删除的副本集成员,则不需要执行进一步的操作。
If, however, a 但是,如果mongos
instance specified the removed member in the --configdb
or configDB
setting, either:mongos
实例在--configdb
或configDB
设置中指定了删除的成员,请执行以下操作之一:
mongos
, ormongos
时更新设置,或