How do I start a replica set without using localhost?

I am trying to initialize a three node replica set. While executing rs.initiate()

, I got the following error: "There is no host described in new configuration 1 for replica set. ##### matches this node"

If I try to set the first item to "localhost: 27017" then I get the following error: "Either all the hostnames in the replica set configuration must be references to localhost, or none must be found 1 of 2"

How should I use my public ip to run a replica set?

+3


source to share


2 answers


What you need to do is prepare the configuration you want to use for the replica set in a document (for example config

) and then pass that document as a parameter to a method rs.initiate(config)

, such as

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

+4


source


You really need to set the directive bindIp:

to your server IP address.

Below you can find the default configuration:



# network interfaces
net:
port: 27017
bindIp: 127.0.0.1

      

0


source







All Articles