码迷,mamicode.com
首页 > 数据库 > 详细

如何重命名MongoDB中的replica set

时间:2019-06-01 13:56:06      阅读:165      评论:0      收藏:0      [点我收藏+]

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

虚拟机里的MongoDB集群全部停掉之后,使用--replSet rs2参数重新启动。mongo shell连进去之后查看状况,

rs1:OTHER> rs.status()
{
        "operationTime" : Timestamp(1559293558, 1),
        "ok" : 0,
        "errmsg" : "Our replica set config is invalid or we are not a member of it",
        "code" : 93,
        "codeName" : "InvalidReplicaSetConfig",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1559293558, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}

重新初始化,还是不行,rs.status()还是老样子

rs.initiate({
   _id : "rs2",
   members: [
      { _id: 0, host: "localhost:51001" },
      { _id: 1, host: "localhost:51002" },
      { _id: 2, host: "localhost:51003" }
   ]
})  

配置信息看起来还正常

rs1:OTHER> rs.conf()
{
        "_id" : "rs1",
        "version" : 1,
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "localhost:51001",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "localhost:51002",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "localhost:51003",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(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")
        }
}

  

看一下log,有这么一段

2019-06-01T11:03:17.078+0800 W REPL [replexec-0] Local replica set configuration document reports set name of rs1, but command line reports rs2; waiting for reconfig or remote heartbeat
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   配置   

原文地址:https://www.cnblogs.com/jerryzh/p/10959320.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!