我在AWS EC2上运行了三个远程实例副本集,并在端口27017上打开了安全组(防火墙),在我的IP上打开了ICMP。
我的开发环境是在Mac OS X上使用PHP 5.6.2的MAMP。 当新的MongoClient在PHP测试文件中时,我提供了一个连接字符串:
的mongodb://52.68.25.131:27017,52.68.29.231:27017,52.68.50.99:27017 / replicaSet = RS0
错误显示:
MongoConnectionException:找不到候选服务器 MongoConnectionException:MongoClient :: __ construct(): php_network_getaddresses:getaddrinfo failed:nodename也没有servname 提供或不知道
仍然无法连接到副本集。以下是我的副本集的状态。
RS0:PRIMARY> rs.status()
{
"set": "rs0",
"date": ISODate("2015-04-09T12:24:15.195Z"),
"myState": 1,
"members": [
{
"_id": 0,
"name": "ip-172-30-0-126:27017",
"health": 1,
"state": 1,
"stateStr": "PRIMARY",
"uptime": 4714,
"optime": Timestamp(1428578838,
1),
"optimeDate": ISODate("2015-04-09T11:27:18Z"),
"electionTime": Timestamp(1428578787,
1),
"electionDate": ISODate("2015-04-09T11:26:27Z"),
"configVersion": 3,
"self": true
},
{
"_id": 1,
"name": "172.30.2.133:27017",
"health": 1,
"state": 2,
"stateStr": "SECONDARY",
"uptime": 3467,
"optime": Timestamp(1428578838,
1),
"optimeDate": ISODate("2015-04-09T11:27:18Z"),
"lastHeartbeat": ISODate("2015-04-09T12:24:14.067Z"),
"lastHeartbeatRecv": ISODate("2015-04-09T12:24:14.821Z"),
"pingMs": 2,
"syncingTo": "ip-172-30-0-126:27017",
"configVersion": 3
},
{
"_id": 2,
"name": "172.30.2.132:27017",
"health": 1,
"state": 2,
"stateStr": "SECONDARY",
"uptime": 3414,
"optime": Timestamp(1428578838,
1),
"optimeDate": ISODate("2015-04-09T11:27:18Z"),
"lastHeartbeat": ISODate("2015-04-09T12:24:13.821Z"),
"lastHeartbeatRecv": ISODate("2015-04-09T12:24:13.818Z"),
"pingMs": 2,
"syncingTo": "172.30.2.133:27017",
"configVersion": 3
}
],
"ok": 1
答案 0 :(得分:0)
将EIP分配给所有三个实例 获得三个公共DNS 并将它们用作副本集的新配置。
来自主节点的rs.reconfig()后,它就像魅力一样。