添加新节点到现有的replica sets中
状态1,执行初始化,代码如下
"stateStr" : "RECOVERING",
"uptime" : 21,
"optime" : {
"t" : 0,
"i" : 0
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2014-07-25T06:35:43Z"),
"pingMs" : 20,
上面可以看到,这个节点还不可用
PRIMARY> rs.status() { "set" : "rs1", "date" : ISODate("2014-07-25T06:37:31Z"), "myState" : 1, "syncingTo" : "localhost:28012", "members" : [ { "_id" : 0, "name" : "localhost:28010", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "optime" : { "t" : 1406270123000, "i" : 1 }, "optimeDate" : ISODate("2014-07-25T06:35:23Z"), "self" : true }, { "_id" : 1, "name" : "localhost:28011", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 11527, "optime" : { "t" : 1406270123000, "i" : 1 }, "optimeDate" : ISODate("2014-07-25T06:35:23Z"), "lastHeartbeat" : ISODate("2014-07-25T06:37:29Z"), "pingMs" : 0 }, { "_id" : 2, "name" : "localhost:28012", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 524, "optime" : { "t" : 1406270123000, "i" : 1 }, "optimeDate" : ISODate("2014-07-25T06:35:23Z"), "lastHeartbeat" : ISODate("2014-07-25T06:37:29Z"), "pingMs" : 0 }, { "_id" : 3, "name" : "localhost:28013", "health" : 1, "state" : 3, "errmsg" : "initial sync couldn't connect to localhost:28012" } ], "ok" : 1
只需要执行
PRIMARY> rs.remove("localhost:28014") PRIMARY> rs.remove("localhost:28014") Fri Jul 25 15:28:32 DBClientCursor::init call() failed Fri Jul 25 15:28:32 query failed : admin.$cmd { replSetReconfig: { _id: "rs1", version: 4, members: [ { _id: 0, host: "localhost:28010" }, { _id: 1, host: "localhost:28011" }, { _id: 2, host: "localhost:28012" }, { _id: 3, host: "localhost:28013" } ] } } to: 127.0.0.1:28010 Fri Jul 25 15:28:32 Error: error doing query: failed shell/collection.js:151 Fri Jul 25 15:28:32 trying reconnect to 127.0.0.1:28010 Fri Jul 25 15:28:32 reconnect 127.0.0.1:28010 ok SECONDARY> show dbs admin (empty) local 1.203125GB test 0.203125GB PRIMARY> rs.remove("localhost:28013") Fri Jul 25 15:29:08 DBClientCursor::init call() failed Fri Jul 25 15:29:08 query failed : admin.$cmd { replSetReconfig: { _id: "rs1", version: 5, members: [ { _id: 0, host: "localhost:28010" }, { _id: 1, host: "localhost:28011" }, { _id: 2, host: "localhost:28012" } ] } } to: 127.0.0.1:28010 Fri Jul 25 15:29:08 Error: error doing query: failed shell/collection.js:151 Fri Jul 25 15:29:08 trying reconnect to 127.0.0.1:28010 Fri Jul 25 15:29:08 reconnect 127.0.0.1:28010 ok rs.status()可看到