Unable to configure replica set

Hi All, I was trying to set a 3 member replica set with mongod running on 3 different servers on Azure with RHEL image. when I was trying add replica members getting error as below:

“Either all host names in a replica set configuration must
be localhost references, or none must be; found 1 out of 2”,“code” : 103,"

Tested by commenting # BindIP in configuration BindIP: 0.0.0.0 or BindIP : of the server but none helped.Could someone advise what should be the BindIP to be set on each of the server as am new to MongoDB.

Sounds like you are using localhost as a hostname for a replica hostname.

The error is telling you all members must be localhost(like a testbed on your local machine) if it sees any member with localhost as the hostname.

You need to use the addressable hostname that the other nodes(and clients) can access the host on.

1 Like

All hosts /etc/hosts been set as hostname.

for eg: Already updated hosts file as below:
10.0.0.1 test1
10.0.0.2 test2
10.0.0.3 test3

Please advise if you are referring this.

No, although that is helpful in being able to resolve them. I am referring to the hosts that are passed as arugments to rs.initiate() or rs.add().

1 Like

Thank you so much Chris for your support on this. Am passing as Hostname only as rs.aadd( “test1”)

You might need to look at what happened with the rs.initiate() the localhost may have been introduced there.

rs.conf() will dump out the current configuration. You can then use rs.reconfigure() with a new configuration document to change the member hostname if it is incorrect.

Thanks a Ton, Chris. After running a reconfig command, was able to add the servers into replica set.

Thank you so much for all your inputs and suggestions.

Thank you so much Chris. Will check by running a reconfig.

could you please advise what value should I mention in BindIP of config file.

should I comment it or specify as 0.0.0.0 or should I mention private IP of the host server.

If it only has one lan ip bindAll. If it is multihomed then pich the network(s) the nodes and app servers are connecting from.

While this has the same outcome for a host with a single IP (and may be more convenient), I’d recommend explicitly binding to the IPs you want mongod to listen to. For a replica set member that would typically be 127.0.0.1 and a private IP.

If additional network interfaces are added in future for some reason (for example, a public IP), limiting IPs might avoid unexpectedly exposing a service that should be private (although there should also be appropriate firewall rules in place).

For available security measures, please review the MongoDB Security Checklist.

Regards,
Stennie

2 Likes