1

Here is my problem. Mongodb works perfectly on my debian 8 server, but I want to do a replica set with external addresses... Here is my problem :
- I have two VPS on a different network
- I followed a tutorial on internet but I have an error message "either all host names in a replica set configuration must be localhost"

Here is a part of my mongodb config :

net:
port: 27017
bindIp: 51.X.X.1, 167.X.X.4

I didn't bind any localhost address. What could I do ? Do I have do do something special to make it works ?

Best Regards

AChichi
  • 322
  • 5
  • 20
  • Your MongoDB config likely doesn't matter here. What matters is when you add members to your replica set. They must either ALL be localhost references, or NONE must be. The question is, what command did you use to add members to your replica set? You should show us those commands so that we can see where the conflict is. – B. Fleming Mar 26 '18 at 21:06
  • Hello thanks for your answer. Here is the commands : rs.initiate() rs.add("51.X.X.1:27017") rs.add("167.X.X.4:27017") I didn't use any localhost address... – AChichi Mar 27 '18 at 11:23
  • Here is the tutorial I used : https://linode.com/docs/databases/mongodb/create-a-mongodb-replica-set/ – AChichi Mar 27 '18 at 11:36

1 Answers1

1

The error message suggests your replica set config includes a localhost address, which was likely added by the default config in rs.initiate() if you didn't explicitly specify localhost anywhere.

You can check the output of rs.conf() to review the current replicate set configuration. Since you want to specify a public hostname I would include your desired config for rs.initiate() rather than relying on the defaults when you initiate the replica set. I'd also recommend following the tutorials in the MongoDB documentation for your server version, as third party tutorials may be outdated or miss important details.

If you want to correct your existing configuration, you could copy the the current replica set config as reported by rs.conf(), edit the hostname or IP address, and then pass the updated configuration document to rs.reconfig().

NOTE: before binding to external IPs, please review the MongoDB Security Checklist and ensure you have configured appropriate security measures like access control, authentication, network encryption (TLS/SSL), and firewall rules. Ideally you would have a VPN/VPC for private communication between your replica set members rather than directly using public networks.

Stennie
  • 63,885
  • 14
  • 149
  • 175