Error adding secondary instance in mongodb replica set

I am trying to install the mongodb replica set. I made an instance of mongodb as the main one from the replica. Now I'm trying to add another mongodb instance hosted on a different iP address as a secondary replica, but I get 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 am I doing wrong?

+7
mongodb replicaset
source share
2 answers

I have to face this problem when I tried to run two mongod instances on the same machine. It throws an error when I provide both

  rs.add("localhost:27027") (or) rs.add("127.0.0.1:27027") 

where 27027 is the port number of the secondary.

Decision:

Pass hostname instead of ip address

  rs.add("myhostname:27027") 
+4
source share

Does the IP address of your newly added replica set point to localhost? Or does your existing member allow localhost? In any case, the replica set will not allow the creation of a mixed localhost / non-localhost configuration.

Take a look at the source code for this post.

In addition, Mongo's sharding guide says the following:

If you use "localhost" or 127.0.0.1 as part of the host name, any host identifier, for example, as the host argument for addShard or the time option value is -configdb, then you should use "localhost" or 127.0.0.1 for all host settings for any MongoDB instances in a cluster. If you mix local addresses and remote host addresses, MongoDB will be an error.

The same applies to replica sets.

0
source share

All Articles