我有两个mongo db节点(节点A和B)的简单设置。这些节点也在运行带有php rest api代码的apache服务器。
下面是两个场景,第二个是问题。
情景1:
1) Node A is mongodb primary and Node B mongodb secondary.
2) REST request sent to Node A, sucessfully processed.
情景2:
1) Node A is mongodb primary and Node B mongodb secondary.
2) REST request sent to Node B, request is processed intermittently.
场景2日志:
PHP Notice: REPLSET INFO: pick server: random element 0 in /var/www/html/api/lib/mongo.php on line 396
PHP Notice: REPLSET INFO: - connection: type: SECONDARY, socket: 42, ping: 0, hash: secondary.host:27017;-;.;27676 in /var/www/html/api/lib/test.php on line 396
PHP Notice: IO FINE: getting reply in /var/www/html/api/lib/test.php on line 396
PHP Notice: IO FINE: getting cursor header in /var/www/html/api/lib/test.php on line 396
PHP Notice: CON FINE: No timeout changes for secondary.host:27017;-;.;27676 in /var/www/html/api/lib/test.php on line 396
PHP Notice: IO FINE: getting cursor body in /var/www/html/api/lib/test.php on line 396
PHP Notice: CON FINE: No timeout changes for secondary.host:27017;-;.;27676 in /var/www/html/api/lib/test.php on line 396
PHP Notice: CON FINE: mongo_connection_destroy: Destroying connection object for secondary.host:27017;-;.;27676 in /var/www/html/api/lib/test.php on line 396
PHP Notice: CON FINE: mongo_connection_destroy: Closing socket for secondary.host:27017;-;.;27676. in /var/www/html/api/lib/test.php on line 396
PHP Fatal error: Uncaught exception 'MongoCursorException' with message 'secondary.host:27017: not master and slaveOk=false'
对于方案2,它应始终选择节点A,但有时它会选择节点B并失败。
PHP代码:
$this->mongo = new \MongoClient ( $list_of_servers, array ('replicaSet' => 'rs0') );
我是否需要进行一些配置更改?如何解决这个问题?
由于
其他信息:
MongoDB Version -> 3.0.6
PHP MongoDB Driver -> 1.6.9
PHP version -> 5.3.3
OS -> RedHat