我正在开发一个使用 MongoDB 副本集来存储我的数据的 PHP Web 应用程序。我偶尔会收到以下错误:
致命错误:未捕获的异常“MongoConnectionException”,消息“未找到候选服务器”
我有一个 3 成员 Mongo 副本集和 1 个仲裁器
rs0:PRIMARY> rs.status()
{
"set" : "rs0",
"date" : ISODate("2013-01-30T01:04:04Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "JenEricsMacPro.local:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 844478,
"optime" : Timestamp(1359507378000, 1),
"optimeDate" : ISODate("2013-01-30T00:56:18Z"),
"self" : true
},
{
"_id" : 1,
"name" : "ericsmacbookpro.local:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 10720,
"optime" : Timestamp(1359507378000, 1),
"optimeDate" : ISODate("2013-01-30T00:56:18Z"),
"lastHeartbeat" : ISODate("2013-01-30T01:04:04Z"),
"pingMs" : 3
},
{
"_id" : 2,
"name" : "ericsmacbookair.local:27017",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 1206,
"lastHeartbeat" : ISODate("2013-01-30T01:04:03Z"),
"pingMs" : 4
},
{
"_id" : 3,
"name" : "ericsmacxps.local:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 75204,
"optime" : Timestamp(1359507378000, 1),
"optimeDate" : ISODate("2013-01-30T00:56:18Z"),
"lastHeartbeat" : ISODate("2013-01-30T01:04:03Z"),
"pingMs" : 1
}
],
"ok" : 1
}
下面是我偶尔收到此错误的代码示例。
$mongoConfig = array (
'uri' => 'mongodb://JenEricsMacPro.local:27017,ericsmacbookpro.local:27017,ericsmacxps.local:27017/',
'database' => 'myDatabase',
'replicaSetArray' => array('replicaSet' => 'rs0'));
$connection = new MongoClient(
$mongoConfig['uri'],
$mongoConfig['replicaSetArray']);
$connection->setReadPreference(MongoClient::RP_SECONDARY_PREFERRED);
$db = $connection->selectDB($mongoConfig['database']);
任何人都知道可能导致“未找到候选服务器”消息的原因或有关如何确定问题根源的任何建议?
我所有的 mongo.conf 文件都使用每台服务器的静态 IP,没有防火墙和 DNS 似乎正确解析到我网络上的 .local 域。
编辑:在实例化 MongoClient 之前,我添加了 Derick 建议的日志记录。
error_reporting (E_NOTICE);
MongoLog::setModule( MongoLog::ALL );
MongoLog::setLevel( MongoLog::ALL );
启用日志记录后,我收到以下通知。
Notice: PARSE INFO: Parsing mongodb://JenEricsMacPro.local:27017,ericsmacbookpro.local:27017,ericsmacxps.local:27017/ in MongoLogic.php on line 27
Notice: PARSE INFO: - Found node: JenEricsMacPro.local:27017 in MongoLogic.php on line 27
Notice: PARSE INFO: - Found node: ericsmacbookpro.local:27017 in MongoLogic.php on line 27
Notice: PARSE INFO: - Found node: ericsmacxps.local:27017 in MongoLogic.php on line 27
Notice: PARSE INFO: - Connection type: MULTIPLE in MongoLogic.php on line 27
Notice: PARSE INFO: - Found option 'replicaSet': 'rs0' in MongoLogic.php on line 27
Notice: PARSE INFO: - Switching connection type: REPLSET in MongoLogic.php on line 27
Notice: CON INFO: mongo_get_read_write_connection: finding a REPLSET connection (read) in MongoLogic.php on line 27
Notice: CON FINE: found connection JenEricsMacPro.local:27017;rs0;X;297 (looking for JenEricsMacPro.local:27017;rs0;X;297) in MongoLogic.php on line 27
Notice: CON INFO: is_ping: pinging JenEricsMacPro.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON FINE: mongo_connection_destroy: Closing socket for JenEricsMacPro.local:27017;rs0;X;297. in MongoLogic.php on line 27
Notice: CON INFO: freeing connection JenEricsMacPro.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON WARN: Couldn't connect to 'JenEricsMacPro.local:27017': send_package: error reading from socket: Operation timed out in MongoLogic.php on line 27
Notice: CON FINE: found connection ericsmacbookpro.local:27017;rs0;X;297 (looking for ericsmacbookpro.local:27017;rs0;X;297) in MongoLogic.php on line 27
Notice: CON INFO: is_ping: pinging ericsmacbookpro.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON FINE: mongo_connection_destroy: Closing socket for ericsmacbookpro.local:27017;rs0;X;297. in MongoLogic.php on line 27
Notice: CON INFO: freeing connection ericsmacbookpro.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON WARN: Couldn't connect to 'ericsmacbookpro.local:27017': send_package: error reading from socket: Operation timed out in MongoLogic.php on line 27
Notice: CON FINE: found connection ericsmacxps.local:27017;rs0;X;297 (looking for ericsmacxps.local:27017;rs0;X;297) in MongoLogic.php on line 27
Notice: CON INFO: is_ping: pinging ericsmacxps.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON FINE: mongo_connection_destroy: Closing socket for ericsmacxps.local:27017;rs0;X;297. in MongoLogic.php on line 27
Notice: CON INFO: freeing connection ericsmacxps.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON WARN: Couldn't connect to 'ericsmacxps.local:27017': send_package: error reading from socket: Operation timed out in MongoLogic.php on line 27
Notice: CON FINE: discover_topology: checking ismaster for JenEricsMacPro.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON WARN: discover_topology: couldn't create a connection for JenEricsMacPro.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON FINE: discover_topology: checking ismaster for ericsmacbookpro.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON WARN: discover_topology: couldn't create a connection for ericsmacbookpro.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON FINE: discover_topology: checking ismaster for ericsmacxps.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: CON WARN: discover_topology: couldn't create a connection for ericsmacxps.local:27017;rs0;X;297 in MongoLogic.php on line 27
Notice: REPLSET FINE: finding candidate servers in MongoLogic.php on line 27
Notice: REPLSET FINE: - all servers in MongoLogic.php on line 27
Notice: REPLSET FINE: filter_connections: adding connections: in MongoLogic.php on line 27
Notice: REPLSET FINE: filter_connections: done in MongoLogic.php on line 27
Notice: REPLSET FINE: limiting to servers with same replicaset name in MongoLogic.php on line 27
Notice: REPLSET FINE: limiting to servers with same replicaset name: done in MongoLogic.php on line 27
Notice: REPLSET FINE: limiting by credentials in MongoLogic.php on line 27
Notice: REPLSET FINE: limiting by credentials: done in MongoLogic.php on line 27