1
votes

No matter how I try to initialize my primary node, it always gets the name "name" : "127.0.0.1:27017", therefore any remote node additions in the replica set, fail with this message:

"errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2"

Here is my .conf

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: mongodb.primary, 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

How should I properly initialize my primary so that it does not bind to 127.0.0.1 only?

The mongodb.primary above is resolvable among all machines;

Here is the full error:

rs0:PRIMARY> rs.add('mongodb.secondary1:27017')
{
    "operationTime" : Timestamp(1552552019, 1),
    "ok" : 0,
    "errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2",
    "code" : 103,
    "codeName" : "NewReplicaSetConfigurationIncompatible",
    "$clusterTime" : {
        "clusterTime" : Timestamp(1552552019, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}
1

1 Answers

2
votes

The problem is clearly stated: the first replica set member is bound to localhost

To bind to all IPs (Not recommended to use this without authentication it's ok for testing though)

net:
  bindIp: 0.0.0.0

See this document here

For you case the chances are that the MongoDB instances at DO are bound to localhost by default. However, you might need to bind them to a different IP address using the net.bindIp configuration option. Please be advised, this wille expose the MongoDB instance being accessible given they connect to the chosen port. Recommended to enable authentication if a MongoDB instance is bound to a different IP than localhost.