'找不到候选服务器'mongo错误

时间:2014-08-26 13:59:15

标签: php apache mongodb

我认为我发现了一个错误的重现,但我无法完全确认它是否存在。我们目前正在使用Mongo php驱动程序的1.5.5版本。我用来重新创建它的步骤如下:

  1. 启动两台mongo服务器并将它们放入副本集
  2. 加载php连接到mongo和副本集
  3. 取下辅助mongo服务器并重新启动
  4. 加载连接到mongo的php。
  5. 我找到了“没有找到候选服务器”但是每10次尝试加载php页面就有一次。重新启动Apache修复了此问题。所以对我而言,这感觉非常类似:

    PHP Mongo Error reading from socket

    但确实说这是固定的。我登录时捕获了这个错误:

    Notice: PARSE INFO: Parsing mongodb://ny1-uutp-fdsa-31:27017,ny1-uutp-fdsa-32:27017 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: PARSE INFO: - Found node: ny1-uutp-fdsa-31:27017 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: PARSE INFO: - Found node: ny1-uutp-fdsa-32:27017 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: PARSE INFO: - Connection type: MULTIPLE in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: PARSE INFO: - Found option 'replicaSet': 'ghood' in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: PARSE INFO: - Switching connection type: REPLSET in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: PARSE INFO: - Found option 'connectTimeoutMS': 120000 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: PARSE WARN: - Replacing previously set value for 'connectTimeoutMS' (60000) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: found connection ny1-uutp-fdsa-31:27017;ghood;.;4523 (looking for ny1-uutp-fdsa-31:27017;ghood;.;4523) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: found connection ny1-uutp-fdsa-32:27017;ghood;.;4523 (looking for ny1-uutp-fdsa-32:27017;ghood;.;4523) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON INFO: mongo_get_read_write_connection: finding a REPLSET connection (read) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: found connection ny1-uutp-fdsa-31:27017;ghood;.;4523 (looking for ny1-uutp-fdsa-31:27017;ghood;.;4523) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON INFO: is_ping: pinging ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: No timeout changes for ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: mongo_connection_destroy: Destroying connection object for ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: mongo_connection_destroy: Closing socket for ny1-uutp-fdsa-31:27017;ghood;.;4523. in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON WARN: Couldn't connect to 'ny1-uutp-fdsa-31:27017': Remote server has closed the connection in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: found connection ny1-uutp-fdsa-32:27017;ghood;.;4523 (looking for ny1-uutp-fdsa-32:27017;ghood;.;4523) in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON INFO: is_ping: pinging ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: No timeout changes for ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: mongo_connection_destroy: Destroying connection object for ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: mongo_connection_destroy: Closing socket for ny1-uutp-fdsa-32:27017;ghood;.;4523. in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON WARN: Couldn't connect to 'ny1-uutp-fdsa-32:27017': Remote server has closed the connection in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: discover_topology: checking ismaster for ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON WARN: discover_topology: couldn't create a connection for ny1-uutp-fdsa-31:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON FINE: discover_topology: checking ismaster for ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: CON WARN: discover_topology: couldn't create a connection for ny1-uutp-fdsa-32:27017;ghood;.;4523 in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: REPLSET FINE: finding candidate servers in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: REPLSET FINE: - all servers in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: REPLSET FINE: - collect any in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: REPLSET FINE: filter_connections: adding connections: in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: REPLSET FINE: filter_connections: done in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: REPLSET FINE: limiting to servers with same replicaset name in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: REPLSET FINE: limiting to servers with same replicaset name: done in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: REPLSET FINE: limiting by credentials in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Notice: REPLSET FINE: limiting by credentials: done in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    
    Fatal error: Uncaught exception 'MongoConnectionException' with message 'No candidate servers found' in /ext1/FIDMGR/sdtk/htdocs/rick.php:8 Stack trace: #0 /ext1/FIDMGR/sdtk/htdocs/rick.php(8): MongoClient->__construct('mongodb://ny1-u...', Array) #1 {main} thrown in /ext1/FIDMGR/sdtk/htdocs/rick.php on line 8
    

    我用来调试的代码非常简单:

    <?
    
    MongoLog::setModule( MongoLog::ALL );
    MongoLog::setLevel( MongoLog::ALL );
    
    error_reporting( E_ALL );
    
    $mongo = new MongoClient('mongodb://ny1-uutp-fdsa-31:27017,ny1-uutp-fdsa-32:27017',Array('replicaSet' => 'ghood', "connectTimeoutMS" => 120000));
    $mongo->setReadPreference(MongoClient::RP_NEAREST);
    
    $userColl = $mongo->user->users;
    
    var_dump($mongo->getConnections);
    var_dump($mongo->getReadPreference());
    

    还有什么我可以研究一下,看看为什么会这样吗?

    这可能是我在这里遇到的设置问题吗?

1 个答案:

答案 0 :(得分:1)

我注意到您的日志显示Couldn't connect to 'ny1-uutp-fdsa-31:27017': Remote server has closed the connection,然后找到ny1-uutp-fdsa-32:27017。但是那个与该服务器的连接也已关闭。然后它尝试找到一个新的主服务器,无法连接到任何一个。所以也许你正在点击正确的错误信息。当您认为只关闭服务器时,您是否意外关闭了两台服务器?

尝试在php.ini中将mongo.is_master_interval降低到1或2秒。这应该有助于PHP更快地寻找新的主服务器。默认值为15秒。

此外,当php驱动程序无法连接到服务器时,它会将其置于黑名单中,并且在mongo.ping_interval到期之前不会再次尝试连接。因此,如果您关闭服务器然后重新启动服务器,则需要很长时间才能再次尝试连接到服务器。默认值为5秒。

我看到你的连接超时是120000,这是两分钟。这似乎也太长了。正如我在你的问题的评论中提到的,我遇到了类似的问题,但我的连接超时只有100毫秒,可能太短了。也许试试5000。

因此,请将ping_interval和is_master_interval调整为几秒钟,然后重新启动apache。还要更改代码以缩短连接超时。确保您只是取下并带回一台服务器。然后等到你的间隔和超时总和已经过去,看看问题是否仍然存在。如果是这样,我认为这可能需要用MongoDB打开一张票。如果在提高连接超时后仍然出现问题,我会告诉您。

我同样阅读了您链接的bug report。我发现MongoLab发布的这些PHP MongoDB驱动程序提示和技巧很有帮助:http://blog.mongolab.com/2014/05/mongodb-driver-tips-tricks-php/