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?
source to share
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
source to share