Rename a Replica Set重命名副本集
On this page本页内容
To rename a replica set, you must shut down all members of the replica set, then configure each member's 要重命名副本集,必须关闭副本集的所有成员,然后使用新的副本集名称配置每个成员的本地数据库。local
database with the new replica set name.
This procedure requires downtime.此过程需要停机。
Prerequisites先决条件
Ensure that your replica set is not sharded. The renaming procedure is for unsharded replica sets only.请确保您的复制副本集没有被分片。重命名过程仅适用于未排序的复制副本集。Before renaming a replica set, perform a full backup of your MongoDB deployment.在重命名副本集之前,请对MongoDB部署执行完整备份。When authentication is enabled, ensure that your user role has启用身份验证后,请确保您的用户角色对每个成员的本地数据库中的find
,insert
, andremove
privileges on thesystem.replset
collection in each member'slocal
database.system.replset
集合具有find
、insert
和remove
权限。
Procedure过程
Shut down replica set members.关闭复制副本集成员。
Follow the procedure in Stop a Replica Set to confirm that replica set members are shut down.按照停止副本集中的过程确认副本集成员已关闭。
This step requires downtime as all replica members will need to be shut down.此步骤需要停机,因为所有复制副本成员都需要关闭。
Rename the replica set.重命名复制副本集。
Perform the following steps for each replica set member:对每个复制副本集成员执行以下步骤:
Start the replica set member on a different port without the在不使用--replSet
option.--replSet
选项的情况下,在其他端口上启动复制副本集成员。Update the replica set name.更新复制副本集名称。If using a configuration file, set如果使用配置文件,请将replication.replSetName
to the new name.replication.replSetName
设置为新名称。If using the如果将mongod
startup command with the--replSet
option, note down the new replica set name for use in step f.mongod
启动命令与--replSet
选项一起使用,请记下在步骤f中使用的新副本集名称。
Connect to the replica set member.连接到复制副本集成员。Update the replica set name in the local database with the following commands:使用以下命令更新本地数据库中的复制副本集名称:/* Set `newId` to the new replica set name */
var newId = '<new replica set name>'
var doc = db.getSiblingDB("local").system.replset.findOne()
var oldId = doc._id
doc._id = newId
db.getSiblingDB("local").system.replset.insertOne(doc)
db.getSiblingDB("local").system.replset.deleteOne({_id: oldId})Shut down the replica set member.关闭复制副本集成员。NoteOps Manager运营经理If you are using Ops Manager, you must stop Ops Manager from managing the replica set before you shut down the replica set member.如果您正在使用Ops Manager,则必须在关闭副本集成员之前停止Ops Manager管理副本集。For more information on this procedure, see Remove a Process from Ops Management有关此过程的更多信息,请参阅从运营管理中删除流程Start the replica set member on its original port.在其原始端口上启动复制副本集成员。If using a configuration file, ensure that如果使用配置文件,请确保replication.replSetName
is set to the new replica set name.replication.replSetName
设置为新的副本集名称。If using the如果将mongod
startup command with the--replSet
option, pass the new name of the replica set to the--replSet
option.mongod
启动命令与--replSet
选项一起使用,请将副本集的新名称传递给--replSet
。