I have created a 3 member replica set in Amazon cloud.I have set all the requires firewall settings and mongo congigurations.Below is my replica set config :
{
"_id" : "rs1",
"version" : 3,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 1,
"host" : "ip-172-31-16-84:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "ip-172-31-23-212:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 3,
"host" : "ip-172-31-14-196:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5720fb585ef3baca32efe765")
}
}
NOTE : I have created the replica set using the machine host name machines public ip address.
i am using below command to connect to replica set from any of these 3 replica set machines and i get connected to primary of the replica set.
mongo --host "rs1/ip-172-31-16-84:27017"
But when i use the same command from any other machine (suppose my local machine) not in same lan . The command fails with below error :
C:\Users\gur35948>mongo --host "rs1/52.221.230.236:27017"
MongoDB shell version: 3.0.6
connecting to: rs1/52.221.230.236:27017/test
2016-04-28T11:54:02.851+0530 I NETWORK starting new replica set monitor for replica set rs1 with seeds 52.221.230.236:27017
2016-04-28T11:54:02.853+0530 I NETWORK [ReplicaSetMonitorWatcher] starting
2016-04-28T11:54:03.043+0530 I NETWORK changing hosts to rs1/ip-172-31-14-196:27017,ip-172-31-16-84:27017,ip-172-31-23-212:27017 from rs1/52.221.230.236:27017
2016-04-28T11:54:13.689+0530 I NETWORK [ReplicaSetMonitorWatcher] getaddrinfo("ip-172-31-14-196") failed: errno:11001 No such host is known.
2016-04-28T11:54:14.335+0530 I NETWORK getaddrinfo("ip-172-31-16-84") failed: errno:11001 No such host is known.
2016-04-28T11:54:16.682+0530 I NETWORK getaddrinfo("ip-172-31-16-84") failed: errno:11001 No such host is known.
2016-04-28T11:54:17.505+0530 I NETWORK getaddrinfo("ip-172-31-14-196") failed:errno:11001 No such host is known.
2016-04-28T11:54:17.505+0530 W NETWORK No primary detected for set rs1
2016-04-28T11:54:17.511+0530 E QUERY Error: ReplicaSetMonitor no master found for set: rs1
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181
The mongo is unable to resolve the hostname used in the replica set because of the difference in the network.I have not used Public Ip because it is bad Practice i guess .
So finally The Question is how do i connect to This remote replica set??
Thanks