我已经建立了一个MongoDB副本集,这是结构:
我在这篇文章的结尾处包含了rs.status()的输出。
我现在遇到的问题是,当我使用MongoDB连接字符串:mongodb://192.168.17.52:27017,192.168.17.223:27017,192.168.17.49:27017/?replicaSet=rs-nnt&readPreference=primary
连接我的应用程序时,如果首先在逗号分隔列表中指定主节点,并且在这种情况下为192.168.17.52,它将可以工作:27017。如果要停止主数据库服务,我希望该应用程序使用辅助节点,但是由于某种原因,它将无法工作,并且在进行了一些故障排除后,我得出的结论是,它将仅使用数据库中指定的第一台主机。连接字符串。
如果需要更多信息,请让我知道,感谢您的帮助!
rs.status():
rs-nnt:PRIMARY> rs.status()
{
"set" : "rs-nnt",
"date" : ISODate("2018-12-04T14:09:38.835Z"),
"myState" : 1,
"term" : NumberLong(8),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1543932576, 1),
"t" : NumberLong(8)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1543932576, 1),
"t" : NumberLong(8)
},
"appliedOpTime" : {
"ts" : Timestamp(1543932576, 1),
"t" : NumberLong(8)
},
"durableOpTime" : {
"ts" : Timestamp(1543932576, 1),
"t" : NumberLong(8)
}
},
"members" : [
{
"_id" : 0,
"name" : "192.168.17.52:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 10565,
"optime" : {
"ts" : Timestamp(1543932576, 1),
"t" : NumberLong(8)
},
"optimeDate" : ISODate("2018-12-04T14:09:36Z"),
"electionTime" : Timestamp(1543923115, 1),
"electionDate" : ISODate("2018-12-04T11:31:55Z"),
"configVersion" : 3,
"self" : true
},
{
"_id" : 1,
"name" : "192.168.17.223:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 8427,
"optime" : {
"ts" : Timestamp(1543932576, 1),
"t" : NumberLong(8)
},
"optimeDurable" : {
"ts" : Timestamp(1543932576, 1),
"t" : NumberLong(8)
},
"optimeDate" : ISODate("2018-12-04T14:09:36Z"),
"optimeDurableDate" : ISODate("2018-12-04T14:09:36Z"),
"lastHeartbeat" : ISODate("2018-12-04T14:09:38.167Z"),
"lastHeartbeatRecv" : ISODate("2018-12-04T14:09:38.736Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "192.168.17.52:27017",
"configVersion" : 3
},
{
"_id" : 2,
"name" : "192.168.17.49:27017",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 10518,
"lastHeartbeat" : ISODate("2018-12-04T14:09:38.167Z"),
"lastHeartbeatRecv" : ISODate("2018-12-04T14:09:36.770Z"),
"pingMs" : NumberLong(0),
"configVersion" : 3
}
],
"ok" : 1,
"operationTime" : Timestamp(1543932576, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1543932576, 1),
"signature" : {
"hash" : BinData(0,"Ydlo0SyUlFlnZUfimAmGvrowuRs="),
"keyId" : NumberLong("6630712219715764225")
}
}
}
其他信息: 防火墙已在所有主机上关闭。 主机名和IP地址已添加到所有服务器上的hosts文件中。