Mongodb – cnames for mongo config server

mongodb

I am seeing this line in many mongoDB links

Use CNAMEs to identify your config servers to the cluster so that you
can rename and renumber your config servers without downtime

I need some help in how set or add CNAMEs to my mongo config servers.

Can anyone help me with a brief explanation on how to implement that in a shard instance?

Best Answer

A Canonical Name record (abbreviated as CNAME record) is a type of resource record in the Domain Name System (DNS) used to specify that a domain name is an alias for another domain, the "canonical" domain.

So, you give a 'dnsname' to your config servers. For example mongoCfg1, mongoCfg2 and mongoCfg3.

Those dns you can register on a dns server, or in the hosts files of your mongo-servers:

mongos:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1   mongos1

10.0.0.10   mongoCfg1
10.0.0.11   mongoCfg2
10.0.0.12   mongoCfg3
10.0.0.13   mongoShard1Repl1
10.0.0.14   mongoShard1Repl2
...

In your mongos config file or startup parameters or even the replication/shard configuration in your mongodb, it is adviced to use those CNAMES.

Example of mongos with cname as configdb parameters:

mongos --configdb mongoCfg1:27019,mongoCfg2:27019,mongoCfg3:27019 --port 27017 --logpath /data/log/log.mongos

In case you need to replace a server, let's say mongoCfg2 needs to be replaced, then you can change the ip for mongoCfg2 in all the hosts files so they will refer to the new config server.