当前位置:Gxlcms > 数据库问题 > 如何重命名MongoDB中的replica set

如何重命名MongoDB中的replica set

时间:2021-07-01 10:21:17 帮助过:13人阅读


2019-06-01T11:03:17.078+0800 I REPL [replexec-0] New replica set config in use: { _id: "rs1", version: 1, protocolVersion: 1, writeConcernMajorityJournalDefault: true, members: [ { _id: 0, host: "localhost:51001", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 }, { _id: 1, host: "localhost:51002", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 }, { _id: 2, host: "localhost:51003", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 } ], settings: { chainingAllowed: true, heartbeatIntervalMillis: 2000, heartbeatTimeoutSecs: 10, electionTimeoutMillis: 10000, catchUpTimeoutMillis: -1, catchUpTakeoverDelayMillis: 30000, getLastErrorModes: {}, getLastErrorDefaults: { w: 1, wtimeout: 0 }, replicaSetId: ObjectId(‘5cf0d661fb9b2ca10d607eca‘) } }
2019-06-01T11:03:17.078+0800 I REPL [replexec-0] This node is not a member of the config
2019-06-01T11:03:17.078+0800 I REPL [replexec-0] transition to REMOVED from STARTUP
2019-06-01T11:03:17.078+0800 I REPL [replexec-0] Starting replication storage threads

 

仔细一看,shell里的提示符,也是rs1。奇怪

那就改下名字吧

https://stackoverflow.com/questions/33400607/how-do-i-rename-a-mongodb-replica-set

 

1. 停止所有实例,使用非复制模式启动

  重新启动,去掉--replSet参数

2. 清除复制集信息缓存数据库local

  使用mongo shell连接到服务器,对3个实例分别执行以下命令  

use local
db.dropDatabase()

3. 停止所有实例,使用复制模式启动

  重新启动,使用--replSet参数指定新的复制集名字

4. 初始化复制集

  a. 使用mongo shell连接到其中一个实例,这个实例将作为新的PRIMARY

  b. 执行rs.initiate()。不要指定参数,不然会报错。其他配置参数可以在随后使用rs.reconfig()方法来设置

  c. 对每一个secondary,使用rs.add("localhost:51002")添加到复制集

  d. 等待secondary同步

 

这种方式不需要重新导入数据

 

如何重命名MongoDB中的replica set

标签:data   catch   iat   启动   opera   复制集   bit   div   配置   

人气教程排行