0

I need to know how I can rename my hosts belonging to my replica environment in mongodb, I currently have the following configuration:

rs.conf()
{
        "_id" : "myreplicaset01",
        "version" : 3,
        "term" : 22,
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "mongodb01.lab.lo:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {
                    },
                    "slaveDelay" : NumberLong(0),
                    "votes" : 1
            },
            {
                    "_id" : 1,
                    "host" : "mongodb02.lab.lo:27017",
                    "arbiterOnly" : false,
                    "buildIndexes" : true,
                    "hidden" : false,
                    "priority" : 1,
                    "tags" : {

                    },
                    "slaveDelay" : NumberLong(0),
                    "votes" : 1
            },
            {
                    "_id" : 2,
                    "host" : "mongodb03.lab.lo:27017",
                    "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("64dc2d0cd950391d47b7972e")
    }

}

I would need to change the hosts for example:

  • "host" : "mongo1:27017"
  • "host" : "mongo2:27017"
  • "host" : "mongo3:27017"

Thanks in advance for the help.

miguel ramires
  • 169
  • 1
  • 5
  • 18

2 Answers2

1

Basically, you need to:

  1. Remove a secondary node from the replica set.
  2. Rename it.
  3. Add it back to the replica set.

And do this in turn for all the nodes that you want to rename. You may also need to do a failover to make a primary node to become a secondary one so that you can remove it from the replica set.

Just a learner
  • 2,082
  • 7
  • 36
  • 57
0

If the node is already reachable by the new name:

conf = rs.config()
conf.members[x].host = "mongox:27017"
rs.reconfig(conf)

Do this for each node, and remember to rs.stepDown() the primary before changing it.

DaPeda
  • 5
  • 2