Josh Elias
Josh Elias

Reputation: 3290

How to start a replica set without using localhost?

I'm trying to initialize a replica set with 3 nodes. While executing rs.initiate() I got the following error: "No host described in new configuration 1 for replica set ##### maps to this node"

If I try to set the first member to "localhost:27017" then I get the following error: "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2"

How am I supposed to use my public ip to initiate the replica set?

Upvotes: 3

Views: 8133

Answers (2)

Alex
Alex

Reputation: 297

You actually need to set your bindIp: directive to your server's IP address.

Below you can find the default config:

# network interfaces
net:
port: 27017
bindIp: 127.0.0.1

Upvotes: 0

Ahmad Hosny
Ahmad Hosny

Reputation: 597

What you need to do is to prepare the configuration that you want to use for the replica set in a document (for example config), and then passing this document as a parameter to the rs.initiate(config) method, like this:

config = {
    _id : "your_replica_set_name",
     members : [
         {_id : 0, host : "yourIpAddress:port1"},
         {_id : 1, host : "yourIpAddress:port2"},
         {_id : 2, host : "yourIpAddress:port3", arbiterOnly: true},
     ]
}

rs.initiate(config)

More details in MongoDB - replSetInitiate command

Upvotes: 4

Related Questions