我只是按照 MongoDB 文档中的说明进行操作
设置 3 节点副本集。当我启动并在主节点中添加第一个节点时,一切顺利。
[foo@host-a mongodb]$ bin/mongo localhost
MongoDB shell version: 1.8.2
connecting to: localhost
> rs.initiate()
{
"info2" : "no configuration explicitly specified -- making one",
"info" : "Config now saved locally. Should come online in about a minute.",
"ok" : 1
}
> rs.add("host-b")
{ "ok" : 1 }
到目前为止一切顺利,但是当我尝试添加第三个节点时
myset:PRIMARY> rs.addArb("host-c")
Sun Aug 7 22:57:09 MessagingPort recv() errno:104 Connection reset by peer 127.0.0.1:27017
Sun Aug 7 22:57:09 SocketException: remote: error: 9001 socket exception [1]
Sun Aug 7 22:57:09 DBClientCursor::init call() failed
Sun Aug 7 22:57:09 query failed : local.$cmd { count: "system.replset", query: {}, fields: {} } to: 127.0.0.1
Sun Aug 7 22:57:09 Error: error doing query: failed shell/collection.js:150
Sun Aug 7 22:57:09 trying reconnect to 127.0.0.1
Sun Aug 7 22:57:09 reconnect 127.0.0.1 ok
结果,当前主服务器变成了次服务器,而主机 b 被标记为死亡,但实际上,它仍然活着。
myset:SECONDARY> rs.status()
{
"set" : "myset",
"date" : ISODate("2011-08-08T04:03:23Z"),
"myState" : 2,
"members" : [
{
"_id" : 0,
"name" : "host-a:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"optime" : {
"t" : 1312775799000,
"i" : 1
},
"optimeDate" : ISODate("2011-08-08T03:56:39Z"),
"self" : true
},
{
"_id" : 1,
"name" : "host-b",
"health" : 0,
"state" : 6,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"t" : 0,
"i" : 0
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2011-08-08T04:03:22Z"),
"errmsg" : "still initializing"
}
],
"ok" : 1
}
怎么会这样?我只是按照文档中的指南操作,难道我做错了什么?而且,我无法在当前辅助服务器上执行任何操作。它不允许我在辅助节点上重新配置,但问题是没有主节点。
myset:SECONDARY> rs.reconfig({})
{
"errmsg" : "replSetReconfig command must be sent to the current replica set primary.",
"ok" : 0
}
有任何想法吗?
答案1
我会做什么:
- 在要保留为次要的系统上,将优先级设置为 0
- 在有问题的系统上,检查其日志。确保它正在监听预期的端口
- 确认所有系统都可以通过问题系统所监听的端口进行连接
- 从配置中删除问题系统,然后重新添加
呼!