shooding
shooding

Reputation: 148

Unreachable MongoDB replica set using MAMP

I'm running three remote instances replica set on AWS EC2 and opened the security group (firewall) on port 27017 and ICMP for my IP.

My developing environment is MAMP with PHP 5.6.2 on Mac OS X. When new MongoClient in PHP test file, I provide a connection string:

mongodb://52.68.25.131:27017,52.68.29.231:27017,52.68.50.99:27017/?replicaSet=rs0

Error shows:

MongoConnectionException: No candidate servers found Caused by MongoConnectionException: MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known

still unable to connect to the replica set. The following is the status of my replica set.


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

Upvotes: 1

Views: 403

Answers (1)

shooding
shooding

Reputation: 148

After assigning EIPs (Elastic IPs) to all three instances to get three public DNS and use them as the new config for replica set.

After rs.reconfig(<new-setting>) from primary node, it works like a charm.

Upvotes: 0

Related Questions