Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while adding a secondary instance in mongodb replica set

I am trying to deploy mongodb replica set . I have made my mongodb instance as primary of the replica . Now i am trying to add another mongodb instance hosted at different iP address, as secondary of the replica, but i am getting the following error :

    rs0:PRIMARY> rs.add("<ip address>:27017")
{
    "ok" : 0,
    "errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2",
    "code" : 103
}

What I am doing wrong ?

like image 602
Anuj Jain Avatar asked Apr 20 '15 11:04

Anuj Jain


1 Answers

Does the IP address of your newly added replica set member resolve to localhost ? Or, does your already existing member resolve to localhost ? Either way, a replica set will not allow mixed localhost / non-localhost configuration.

Take a look at the source code location of this message.

Also, the Mongo guide on sharding says this:

If you use either “localhost” or 127.0.0.1 as the hostname portion of any host identifier, for example as the host argument to addShard or the value to the --configdb run time option, then you must use “localhost” or 127.0.0.1 for all host settings for any MongoDB instances in the cluster. If you mix localhost addresses and remote host address, MongoDB will error.

The same applies for replica sets.

like image 143
Kai Sternad Avatar answered Oct 04 '22 06:10

Kai Sternad