@Stefano 给了你答案。我想补充几点:
问题 1:
您可以使用rs.status查看副本集状态。这样主次分清了。
{
"set" : "replset",
"date" : ISODate("2015-11-19T15:22:32.597Z"),
"myState" : 1,
"term": NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"members" : [
{
"_id" : 0,
"name" : "m1.example.net:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 269,
"optime" : {
"ts" : Timestamp(1447946550, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2015-11-19T15:22:30Z"),
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1447946549, 1),
"electionDate" : ISODate("2015-11-19T15:22:29Z"),
"configVersion" : 1,
"self" : true
},
{
"_id" : 1,
"name" : "m2.example.net:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 13,
"optime" : {
"ts" : Timestamp(1447946539, 1),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("2015-11-19T15:22:19Z"),
"lastHeartbeat" : ISODate("2015-11-19T15:22:31.323Z"),
"lastHeartbeatRecv" : ISODate("2015-11-19T15:22:32.045Z"),
"pingMs" : NumberLong(0),
"configVersion" : 1
},
{
"_id" : 2,
"name" : "m3.example.net:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 13,
"optime" : {
"ts" : Timestamp(1447946539, 1),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("2015-11-19T15:22:19Z"),
"lastHeartbeat" : ISODate("2015-11-19T15:22:31.325Z"),
"lastHeartbeatRecv" : ISODate("2015-11-19T15:22:31.971Z"),
"pingMs" : NumberLong(0),
"configVersion" : 1
}
],
"ok" : 1
}
了解slave延时火rs.printSlaveReplicationInfo():
source: localhost.localdomain:27070
syncedTo: Mon May 02 2016 12:34:36 GMT+0530 (IST)
0 secs (0 hrs) behind the primary
source: localhost.localdomain:27072
syncedTo: Mon May 02 2016 12:34:36 GMT+0530 (IST)
0 secs (0 hrs) behind the primary
source: localhost.localdomain:27073
syncedTo: Mon May 02 2016 12:34:36 GMT+0530 (IST)
0 secs (0 hrs) behind the primary
要在 oplog 中了解有关复制追赶的更多详细信息,请尝试rs.printReplicationInfo():
configured oplog size: 700.0038909912109MB
log length start to end: 261920secs (72.76hrs)
oplog first event time: Fri Apr 29 2016 11:49:16 GMT+0530 (IST)
oplog last event time: Mon May 02 2016 12:34:36 GMT+0530 (IST)
now: Mon May 02 2016 12:49:37 GMT+0530 (IST)
问题 2:
奇数副本有助于在选举中进行高投票。因此,如果您有偶数副本集,您可以添加Arbiters。它们只是重量轻且不包含数据,它们也可以驻留在任何其他当前正在运行的服务器上。
希望这会有所帮助!!!