我在亚马逊云中创建了一个 3 成员副本集。我已经设置了所有需要的防火墙设置和 mongo 配置。下面是我的副本集配置:
{
"_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")
}
}
注意:我已经使用机器主机名机器公共 IP 地址创建了副本集。
我正在使用以下命令从这 3 台副本集机器中的任何一台连接到副本集,并且我连接到副本集的主节点。
mongo --host "rs1/ip-172-31-16-84:27017"
但是当我从不在同一个局域网中的任何其他机器(假设我的本地机器)上使用相同的命令时。该命令失败并出现以下错误:
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
由于网络的差异,mongo 无法解析副本集中使用的主机名。我没有使用公共 IP,因为我猜这是不好的做法。
所以最后的问题是我如何连接到这个远程副本集?
谢谢