>rs.initiate(cfg)
输出:
{
"ok" : 1,
"operationTime" : Timestamp(1521190572, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1521190572, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
>rs.status()
输出:
{
"set" : "testrs",
"date" : ISODate("2018-03-16T08:56:23.948Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"appliedOpTime" : {
"ts" : Timestamp(1521190572, 1),
"t" : NumberLong(-1)
},
"durableOpTime" : {
"ts" : Timestamp(1521190572, 1),
"t" : NumberLong(-1)
}
},
"members" : [
{
"_id" : 0,
"name" : "server1:27001",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 220,
"optime" : {
"ts" : Timestamp(1521190572, 1),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("2018-03-16T08:56:12Z"),
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1521190582, 1),
"electionDate" : ISODate("2018-03-16T08:56:22Z"),
"configVersion" : 1,
"self" : true
},
{
"_id" : 1,
"name" : "server2:27001",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 11,
"optime" : {
"ts" : Timestamp(1521190572, 1),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(1521190572, 1),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("2018-03-16T08:56:12Z"),
"optimeDurableDate" : ISODate("2018-03-16T08:56:12Z"),
"lastHeartbeat" : ISODate("2018-03-16T08:56:22.733Z"),
"lastHeartbeatRecv" : ISODate("2018-03-16T08:56:19.659Z"),
"pingMs" : NumberLong(0),
"configVersion" : 1
},
{
"_id" : 2,
"name" : "server3:27001",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 11,
"optime" : {
"ts" : Timestamp(1521190572, 1),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(1521190572, 1),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("2018-03-16T08:56:12Z"),
"optimeDurableDate" : ISODate("2018-03-16T08:56:12Z"),
"lastHeartbeat" : ISODate("2018-03-16T08:56:22.733Z"),
"lastHeartbeatRecv" : ISODate("2018-03-16T08:56:19.641Z"),
"pingMs" : NumberLong(0),
"configVersion" : 1
}
],
"ok" : 1,
"operationTime" : Timestamp(1521190572, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1521190582, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
可以看到priority值越大的节点越有可能成为primary。
好了,相信大家对Replica Set已经有了初步体验和认识,如果上文中有什么表述的不准备或者错误的地方,欢迎指出,大家共同探讨进步。