How to rename a replica set MongoDB in

After all the virtual machines in a cluster of MongoDB stopped using the restart --replSet rs2 parameters. mongo shell to view status even go after,

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)
                }
        }
}

Re-initialized or not, rs.status () is still the same

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

Also look normal configuration information

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")
        }
}

  

Look at the log, has this to say

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

 

Look closely, shell in the prompt, also rs1. strange

That changed under the name of it

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

 

1. Stop all instances, the use of non-replicating mode is activated

  Restart, remove --replSet parameters

2. Clear the local cache database replication set information

  Use mongo shell connected to the server, the following are three examples of command  

use local
db.dropDatabase()

3. Stop all instances, use the copy mode is activated

  Restart, use --replSet parameter to specify the name of the new replication set

4. Initialize replication set

  a. Using mongo shell connected to one instance, which will serve as the new PRIMARY

  b. Perform rs.initiate (). Do not specify parameters, or will be error. Other configuration parameters may be provided in a subsequent use rs.reconfig () method

  . C for each secondary, using rs.add ( "localhost: 51002") set to the replication

  d. Wait secondary synchronization

 

This approach does not require re-import data

 

Guess you like

Origin www.cnblogs.com/jerryzh/p/10959320.html