我有一个包含 2 个服务器(一个数据服务器和一个仲裁器)的副本集。rs.status() 显示所有三个服务器都已连接。
但是当我停止主服务器时,辅助服务器仍保持辅助状态并且不会成为主服务器。
可能存在什么问题?
停止主服务器之前,rs.status():
r6:SECONDARY> rs.status()
{
"set" : "r6",
"date" : ISODate("2018-05-30T08:57:23.195Z"),
"myState" : 2,
"term" : NumberLong(5),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1527669880, 1),
"t" : NumberLong(4)
},
"appliedOpTime" : {
"ts" : Timestamp(1527669880, 1),
"t" : NumberLong(4)
},
"durableOpTime" : {
"ts" : Timestamp(1527669880, 1),
"t" : NumberLong(4)
}
},
"members" : [
{
"_id" : 0,
"name" : "node14.company.biz:27118",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 10,
"optime" : {
"ts" : Timestamp(1527670641, 1),
"t" : NumberLong(5)
},
"optimeDurable" : {
"ts" : Timestamp(1527670641, 1),
"t" : NumberLong(5)
},
"optimeDate" : ISODate("2018-05-30T08:57:21Z"),
"optimeDurableDate" : ISODate("2018-05-30T08:57:21Z"),
"lastHeartbeat" : ISODate("2018-05-30T08:57:22.613Z"),
"lastHeartbeatRecv" : ISODate("2018-05-30T08:57:22.230Z"),
"pingMs" : NumberLong(0),
"electionTime" : Timestamp(1527670640, 1),
"electionDate" : ISODate("2018-05-30T08:57:20Z"),
"configVersion" : 3
},
{
"_id" : 1,
"name" : "node15:27139",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 840,
"optime" : {
"ts" : Timestamp(1527669880, 1),
"t" : NumberLong(4)
},
"optimeDate" : ISODate("2018-05-30T08:44:40Z"),
"configVersion" : 3,
"self" : true
},
{
"_id" : 2,
"name" : "node16:27159",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 837,
"lastHeartbeat" : ISODate("2018-05-30T08:57:22.240Z"),
"lastHeartbeatRecv" : ISODate("2018-05-30T08:57:19.752Z"),
"pingMs" : NumberLong(0),
"configVersion" : 3
}
],
"ok" : 1
}
我停止主要操作后 rs.status():
r6:SECONDARY> rs.status()
{
"set" : "r6",
"date" : ISODate("2018-05-30T08:58:58.612Z"),
"myState" : 2,
"term" : NumberLong(5),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1527670731, 1),
"t" : NumberLong(5)
},
"appliedOpTime" : {
"ts" : Timestamp(1527670731, 1),
"t" : NumberLong(5)
},
"durableOpTime" : {
"ts" : Timestamp(1527670731, 1),
"t" : NumberLong(5)
}
},
"members" : [
{
"_id" : 0,
"name" : "node14.company.biz:27118",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2018-05-30T08:58:55.409Z"),
"lastHeartbeatRecv" : ISODate("2018-05-30T08:58:54.257Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Connection refused",
"configVersion" : -1
},
{
"_id" : 1,
"name" : "node15:27139",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 935,
"optime" : {
"ts" : Timestamp(1527670731, 1),
"t" : NumberLong(5)
},
"optimeDate" : ISODate("2018-05-30T08:58:51Z"),
"infoMessage" : "could not find member to sync from",
"configVersion" : 3,
"self" : true
},
{
"_id" : 2,
"name" : "node16:27159",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 932,
"lastHeartbeat" : ISODate("2018-05-30T08:58:55.407Z"),
"lastHeartbeatRecv" : ISODate("2018-05-30T08:58:54.760Z"),
"pingMs" : NumberLong(0),
"configVersion" : 3
}
],
"ok" : 1
}
答案1
解决了!
问题是每个主机都知道自己的 DNS 后缀,如“node08.company.biz”,而我向没有此后缀的副本集添加了服务器和仲裁器(如“node08”)。
我使用不带后缀的名称重新配置了每个副本集,现在它可以正常工作