我已经设置了一个副本集,并希望将其添加到 mongos 中。但我在 mongos 中遇到以下错误:
mongos> sh.addShard("rs3/172.19.0.12:27017,172.19.0.6:27017,172.19.0.5:27017")
{
"code" : 11000,
"ok" : 0,
"errmsg" : "E11000 duplicate key error collection: admin.system.version index: _id_ dup key: { : \"shardIdentity\" }"
}
从上面的消息中,它说admin.system.version
有重复的键错误。集合admin.system.version
应该由 mongodb 设置。我不明白为什么它有一个重复的键。
所有 mongo 实例都是 3.4.4 版本。
以下是副本集状态:
rs3:PRIMARY> rs.status()
{
"set" : "rs3",
"date" : ISODate("2017-07-09T02:13:37.146Z"),
"myState" : 1,
"term" : NumberLong(10),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"appliedOpTime" : {
"ts" : Timestamp(1499566407, 1),
"t" : NumberLong(10)
},
"durableOpTime" : {
"ts" : Timestamp(1499563905, 1),
"t" : NumberLong(9)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.19.0.12:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 2493,
"optime" : {
"ts" : Timestamp(1499566407, 1),
"t" : NumberLong(10)
},
"optimeDate" : ISODate("2017-07-09T02:13:27Z"),
"electionTime" : Timestamp(1499563936, 1),
"electionDate" : ISODate("2017-07-09T01:32:16Z"),
"configVersion" : 414750,
"self" : true
},
{
"_id" : 1,
"name" : "172.19.0.5:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1403,
"optime" : {
"ts" : Timestamp(1499566407, 1),
"t" : NumberLong(10)
},
"optimeDurable" : {
"ts" : Timestamp(1499563905, 1),
"t" : NumberLong(9)
},
"optimeDate" : ISODate("2017-07-09T02:13:27Z"),
"optimeDurableDate" : ISODate("2017-07-09T01:31:45Z"),
"lastHeartbeat" : ISODate("2017-07-09T02:13:35.870Z"),
"lastHeartbeatRecv" : ISODate("2017-07-09T02:13:35.854Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "172.19.0.12:27017",
"configVersion" : 414750
},
{
"_id" : 2,
"name" : "172.19.0.6:27017",
"health" : 1,
"state" : 3,
"stateStr" : "RECOVERING",
"uptime" : 2487,
"optime" : {
"ts" : Timestamp(1499070510, 1000),
"t" : NumberLong(3)
},
"optimeDurable" : {
"ts" : Timestamp(1499070510, 1000),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2017-07-03T08:28:30Z"),
"optimeDurableDate" : ISODate("2017-07-03T08:28:30Z"),
"lastHeartbeat" : ISODate("2017-07-09T02:13:35.865Z"),
"lastHeartbeatRecv" : ISODate("2017-07-09T02:13:36.965Z"),
"pingMs" : NumberLong(0),
"configVersion" : 414750
}
],
"ok" : 1
}
问题是您的副本集(rs3)已经或者它是其他集群的一部分!从未连接到分片的副本集没有该文档。
admin.system.version
当集群在连接到集群的过程中尝试将此文档添加到此时,会出现错误。如果您查询该集合,您可以看到 RS 认为它属于“哪个”集群。
如果您知道此 rs3 不属于任何其他集群,则可以直接连接到该副本集并从 admin.system.version -collection 中删除该文档。之后,mongoS 上的 addShard 命令应该可以正常工作。