我目前在复制集中有4个mongo实例,其中一个是过时的,需要删除,但是当我运行rs.remove("hostname")
时,我的django应用程序立即开始抛出Node is not in primary or recovering state upon removal of instance from replication set
,直到我添加实例回来了。
这是我的rs.status()
rs_pimapi:PRIMARY> rs.status()
{
"set" : "rs_pimapi",
"date" : ISODate("2017-07-28T01:27:05.607Z"),
"myState" : 1,
"term" : NumberLong(-1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1501205225, 1),
"t" : NumberLong(-1)
},
"appliedOpTime" : Timestamp(1501205225, 1),
"durableOpTime" : Timestamp(1501205222, 1)
},
"members" : [
{
"_id" : 25,
"name" : "10.231.158.108:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 7212131,
"optime" : Timestamp(1501205225, 1),
"optimeDate" : ISODate("2017-07-28T01:27:05Z"),
"electionTime" : Timestamp(1500629818, 1),
"electionDate" : ISODate("2017-07-21T09:36:58Z"),
"configVersion" : 278273,
"self" : true
},
{
"_id" : 29,
"name" : "10.0.1.95:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 20216,
"optime" : Timestamp(1501205222, 1),
"optimeDurable" : Timestamp(1501205222, 1),
"optimeDate" : ISODate("2017-07-28T01:27:02Z"),
"optimeDurableDate" : ISODate("2017-07-28T01:27:02Z"),
"lastHeartbeat" : ISODate("2017-07-28T01:27:04.286Z"),
"lastHeartbeatRecv" : ISODate("2017-07-28T01:27:04.373Z"),
"pingMs" : NumberLong(1),
"syncingTo" : "10.231.158.108:27017",
"configVersion" : 278273
},
{
"_id" : 30,
"name" : "10.0.0.213:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 14382,
"optime" : Timestamp(1501205222, 1),
"optimeDurable" : Timestamp(1501205222, 1),
"optimeDate" : ISODate("2017-07-28T01:27:02Z"),
"optimeDurableDate" : ISODate("2017-07-28T01:27:02Z"),
"lastHeartbeat" : ISODate("2017-07-28T01:27:04.380Z"),
"lastHeartbeatRecv" : ISODate("2017-07-28T01:27:04.401Z"),
"pingMs" : NumberLong(1),
"syncingTo" : "10.0.1.95:27017",
"configVersion" : 278273
},
{
"_id" : 31,
"name" : "10.124.225.51:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 6595,
"optime" : Timestamp(1501205222, 1),
"optimeDurable" : Timestamp(1501205222, 1),
"optimeDate" : ISODate("2017-07-28T01:27:02Z"),
"optimeDurableDate" : ISODate("2017-07-28T01:27:02Z"),
"lastHeartbeat" : ISODate("2017-07-28T01:27:03.679Z"),
"lastHeartbeatRecv" : ISODate("2017-07-28T01:27:03.716Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "10.0.0.213:27017",
"configVersion" : 278273
}
],
"ok" : 1
}
rs.config()
{
"_id" : "rs_pimapi",
"version" : 278273,
"members" : [
{
"_id" : 25,
"host" : "10.231.158.108:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 29,
"host" : "10.0.1.95:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0.5,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 30,
"host" : "10.0.0.213:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 31,
"host" : "10.124.225.51:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 2000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
}
}
}
在我的django设置中,我将副本设置为
REPLICA_HOSTS = 'mongodb://10.231.158.108,10.0.1.95,10.0.0.51'
当我尝试删除10.124.225.51
时出现的问题,在配置中没有引用,并且我对复制集的理解应该能够安全地取出。