Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 547
Josh Elias Avatar asked Jan 02 '26 07:01

Josh Elias


1 Answers

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

like image 97
compuhosny Avatar answered Jan 03 '26 19:01

compuhosny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!