How can I connect to my replicaset via DNS and private IP?
1
vote
0
answers
224
views
I have 2 node setup
10.1.0.7 - mongodb-1.com (primary)
10.1.0.8 - mongodb-2.com (secondary)
here is my mongod.conf
net:
port: 27017
bindIp: 0.0.0.0
tls:
mode: allowTLS
certificateKeyFile: /etc/mongodb/certificates/mongodb.pem
security:
authorization: enabled
keyFile: /home/dbuser/repset
replication:
replSetName: "repset"
here is my rs.conf()
{
_id: 'repset',
version: 4,
term: 3,
members: [
{
_id: 0,
host: '10.1.0.7:27017',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long("0"),
votes: 1
},
{
_id: 1,
host: '10.1.0.8:27017',
arbiterOnly: false,
buildIndexes: true,
hidden: false,
priority: 1,
tags: {},
secondaryDelaySecs: Long("0"),
votes: 1
}
],
protocolVersion: Long("1"),
writeConcernMajorityJournalDefault: true,
settings: {
chainingAllowed: true,
heartbeatIntervalMillis: 2000,
heartbeatTimeoutSecs: 10,
electionTimeoutMillis: 10000,
catchUpTimeoutMillis: -1,
catchUpTakeoverDelayMillis: 30000,
getLastErrorModes: {},
getLastErrorDefaults: { w: 1, wtimeout: 0 },
replicaSetId: ObjectId("641aebeb4623f6fd0e700cf2")
}
}
Now my proposed setup would be there are 2 application servers that will connect to this replica set. 1 is via private IP and the other is via DNS name. Now when I connect via private IP. it is working fine. I cant do the same when connecting via DNS name. is that possible?
I am connecting to this via this script below (via Private IP that's working)
mongodb://username:password@10.1.0.7:27017,10.1.0.8:27017/?authSource=admin&replicaSet=repset
The script below is the one that could not connect (via DNS)
mongodb://username:password@mongodb-1.com:27017,mongodb-2.com:27017/?authSource=admin&replicaSet=repset
UPDATE: I do not know why this works but when I try to add each domain name as replicaset members.
rs.add('mongodb-1.com:27017')
rs.add('mongodb-2.com:27017')
I am now able to connect publicly via this command
mongodb://username:password@mongodb-1.com:27017,mongodb-2.com:27017/?authSource=admin&replicaSet=repset
Asked by JRA
(137 rep)
Mar 29, 2023, 07:58 AM
Last activity: Apr 27, 2023, 12:38 PM
Last activity: Apr 27, 2023, 12:38 PM