【发布时间】:2014-04-23 22:30:56
【问题描述】:
规格:PHP 5.3.10、Ubuntu 12.04 64 位、Mongo 驱动程序 1.5.1、MongoDB 2.4.8
我们有一个带有两个辅助副本集的 Mongo 分片。我似乎无法让 PHP 驱动程序利用副本集进行高性能读/写。尝试使用下面提供的连接字符串进行连接时,我收到“未找到候选服务器”。
$connection = new MongoClient("mongodb://10.88.217.247:27017,10.88.217.247:27018",
array('username'=>"{$username}", 'password'=>"{$password}", 'replicaSet' => true));
这是 Mongo 日志发送的内容:
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: start
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] send_packet: read from header: 36
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] send_packet: data_size: 259
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: can't find minWireVersion, defaulting to 0
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: can't find maxWireVersion, defaulting to 0
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: setting maxBsonObjectSize to 16777216
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: setting maxMessageSizeBytes to 48000000
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: can't find maxWriteBatchSize, defaulting to 1000
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: set name: rs-0, ismaster: 1, secondary: 0, is_arbiter: 0
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: the server name (mongo-0-0:27018) did not match with what we thought it'd be (10.88.218.248:27018).
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: the replicaset name is not set, so we're using rs-0.
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] found host: mongo-0-0:27018
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] found host: mongo-0-2:27018
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] found host: mongo-0-1:27018
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] ismaster: last ran at 1398292169
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] discover_topology: ismaster worked, but we need to remove the seed host's connection
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] mongo_connection_destroy: Destroying connection object for 10.88.218.248:27018;-;admin/scal/a6612d715d1a4f9549232ec4d599bf55;12199
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] mongo_connection_destroy: Closing socket for 10.88.218.248:27018;-;admin/scal/a6612d715d1a4f9549232ec4d599bf55;12199.
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] discover_topology: ismaster worked
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] discover_topology: found new host: mongo-0-0:27018
[Wed Apr 23 22:29:29 2014] [error] [client 170.171.2.122] connection_create: creating new connection for mongo-0-0:27018
rs.status() JSON:
{
"set" : "rs-0",
"date" : ISODate("2014-04-24T15:13:39.000Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "mongo-0-0:27018",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 68415,
"optime" : Timestamp(1398285029, 1),
"optimeDate" : ISODate("2014-04-23T20:30:29.000Z"),
"self" : true
},
{
"_id" : 1,
"name" : "mongo-0-1:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 67984,
"optime" : Timestamp(1398285029, 1),
"optimeDate" : ISODate("2014-04-23T20:30:29.000Z"),
"lastHeartbeat" : ISODate("2014-04-24T15:13:38.000Z"),
"lastHeartbeatRecv" : ISODate("2014-04-24T15:13:38.000Z"),
"pingMs" : 0,
"syncingTo" : "mongo-0-0:27018"
},
{
"_id" : 3,
"name" : "mongo-0-2:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 63419,
"optime" : Timestamp(1398285029, 1),
"optimeDate" : ISODate("2014-04-23T20:30:29.000Z"),
"lastHeartbeat" : ISODate("2014-04-24T15:13:38.000Z"),
"lastHeartbeatRecv" : ISODate("2014-04-24T15:13:38.000Z"),
"pingMs" : 0,
"syncingTo" : "mongo-0-0:27018"
}
],
"ok" : 1
}
【问题讨论】:
-
我不知道这是否重要,但你会在你的问题中编辑你的 PHP 版本和你的操作系统平台吗?对于可能涉及平台错误的问题,值得养成添加此数据的习惯,以防有用。
-
我不知道 Mongo,但是“未设置副本集名称,所以我们使用 rs-0”是否相关?这是否意味着副本集需要进一步配置?
-
尝试运行 rs.status() 并将结果粘贴到您的问题中
-
刚刚发布了 rs.status() 的输出,谢谢。
-
这不是完整的 mongolog 输出。完整输出将包含导致您遇到异常的连接选择逻辑详细信息。请粘贴完整的日志。此外,您将布尔值 true 传递给“replSet”,这不是您想要的(如日志所示)。请改为传递副本集名称。