Reputation: 155
I have 3 instances on EC2, each with elastic IP, and each running mongo version 3.2. All are in the replica set by the type name. The bind_ip settings in mongod.conf are configured with the IP 0.0.0.0.
I'm trying to connect mongo through php. I already have installed the extension mongodb and library.
All of which are on the same port, and the primary IP: 52.67.34.1
My connection:
$this->manager = new MongoDB\Driver\Manager(
"mongodb://52.67.34.1,52.67.77.2,52.67.30.3/?replicaSet=homologation");
But to do query or insert, it gives the following error:
Fatal error: Uncaught exception 'MongoDB \ Driver \ Exception \ ConnectionTimeoutException' with message 'No suitable servers found (
serverselectiontryonce
set): [connection error calling ismaster on '52.67.34.1:27017'] [connection error calling ismaster on '52.67.77.2:27017'] [connection error calling ismaster on '52.67.30.3:27017'] [Failed connecting to '172.31.1.1:27017': Connection timed out] [Failed connecting to '172.31.2.2:27017': Connection timed out] [Failed connecting to '172.31.3.3:27017': Connection timed out]
How do I fix this error? Connect to mongo?
Upvotes: 0
Views: 1241
Reputation: 106
I had issues connecting to replica set in PHP with the machine IPs, and solved this using the machine hosts.
If you don't have your server hosts in your DNS (public or private), I would suggest to declare each replica member in the /etc/hosts file.
It worked for me, and I hope it'll help.
Upvotes: 1