Changing hostname IP address in mongodb configuration

Posted on

Question :

My mongodb sharded cluster is set with 1-member replica set for config server with 6 shards, 1 mongos. All these components are hosted on a single server with mongos on 0.0.0.0:27017 and rest on 127.0.0.1. All addresses have been configured through hostnames in /etc/hosts i.e 127.0.0.1 as configrs , 0.0.0.0 as mongos and bindIP in mongo config holds these hostnames and not IP addresses.

I want to host a mongos on separate server. Since config server was hosted on 127.0.0.1:27018, to make it reachable I stopped the config mongo, updated /etc/hosts contents from 127.0.0.1 configrs to 0.0.0.0 configrs and restarted the config mongo. But now, rs.status() returns

“state” : 10,
“stateStr” : “REMOVED”,
“uptime” : 12,
“optime” : {
“ts” : Timestamp(1521449062, 2),
“t” : NumberLong(3)
},
“optimeDate” : ISODate(“2018-03-19T08:44:22Z”),
“ok” : 0,
“errmsg” : “Our replica set config is invalid or we are not a member of it”,
“code” : 93,
“codeName” : “InvalidReplicaSetConfig”

How do I move my config server from 127.0.0.1 to 0.0.0.0? I went through hostname change documentation for mongo, but it lists down steps to change hostnames whereas I am not changing hostname.

Answer :

Address 0.0.0.0 (itself) don’t exists.

It is used at config files as value what means “listen all network devices”.

If you want to have mongos at different server, you need to configure your cluster to use address what is connected to network device what point outside world (maybe eth0). All components of that cluster (config server, all shards) must be using that “external” IP-address what is reachable from that machine where you are going to put that mongos.

How to change all components to use external IP address? It is possible to do “under the hood”, but to you it would be easier to export all data to HD, rebuild your cluster with right configuration and then import data back to cluster.

You should take a look at the mongodb reference
https://docs.mongodb.com/manual/tutorial/change-hostnames-in-a-replica-set/

To summarize, you have to update system.replset collection under local database.

Once config replicaset dbs are back to online,
You need to check mongos startup parameter such as “configdb”

Leave a Reply

Your email address will not be published. Required fields are marked *