add new mongo replica from other server with public ip

  Kiến thức lập trình

I am trying to set up a MongoDB replica with different servers. For example, in Server A, I have 2 MongoDB instances on port 27017 and 27018, and in Server B I have one instance on port 27020. I have successfully set up the replica for these servers in a private network.

rs.initiate( {
   _id : "tsrs0",
   members: [
      { _id: 0, host: "192.168.130.10:27017" }, // server A
      { _id: 1, host: "192.168.130.10:27018" }, // server A
      { _id: 2, host: "192.168.130.11:27020" }  // server B
   ]
})

Now, I want to add another node in Server C that does not have a physical link or private network with Server A and B. I tried to NAT a private IP and port, like 192.168.130.12:27021 from Server A to a public IP from Server C, and then add this 192.168.130.12:27021 to the replica.

I added it without any errors, but when I get rs.status() on the master, it shows “stateStr” : “STARTUP” for the new node. What could be the problem?
Since the MongoDB server is running in production, I cannot change private IPs to hostnames.

LEAVE A COMMENT