全部博文(150)
分类: NOSQL
2018-02-28 11:52:37
设置/etc/mongod.conf 保持和复制集其他节点相同
保证本机mongod可以正常启动
复制集primary节点操作
##执行增加命令 xxx:PRIMARY> rs.add({host: "10.2.1.10:27017", priority: 0, votes:0 }) { "ok" : 1 } ##查看增加后的状态 xxx:PRIMARY> rs.status() { ...... { "_id" : 5, "name" : "10.2.1.10:27017", "health" : 1, "state" : 5, "stateStr" : "STARTUP2", "uptime" : 458, "optime" : Timestamp(0, 0), "optimeDurable" : Timestamp(0, 0), "optimeDate" : ISODate("1970-01-01T00:00:00Z"), "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"), "lastHeartbeat" : ISODate("2018-02-27T03:20:09.888Z"), "lastHeartbeatRecv" : ISODate("2018-02-27T03:20:11.538Z"), "pingMs" : NumberLong(34), "syncingTo" : "10.0.1.32:27017", "configVersion" : 14 } ], "ok" : 1 }
goluk:OTHER> rs.status() { { "_id" : 5, "name" : "10.2.1.10:27017", "health" : 1, "state" : 5, "stateStr" : "STARTUP2", "uptime" : 5052, "optime" : Timestamp(0, 0), "optimeDate" : ISODate("1970-01-01T00:00:00Z"), "syncingTo" : "10.0.1.32:27017", "configVersion" : 14, "self" : true } ], "ok" : 1 }
查看本地节点的mongod.log
发现已经开始初始化同步数据
2018-02-27T11:14:20.940+0800 I REPL [repl writer worker 1] CollectionCloner::start called, on ns:a6.a6_apk_version 2018-02-27T11:14:21.034+0800 I INDEX [InitialSyncInserters-a6.a6_apk_version0] build index on: a6.a6_apk_version properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "a6.a6_apk_version" }
剩下的就喝茶等同步完成
修改本地节点的priority和votes
远程节点不参与投票,只做数据备份
rs.reconfig()会导致当前primary降级并引发新的选举。选举期间所有客户端的连接会被断开,并持续10-20秒。因此应在例行维护期间执行该命令
cfg = rs.conf()
cfg.members[4].priority = 0
rs.reconfig(cfg)
xxx:PRIMARY> rs.remove("192.168.1.230:27017") { "ok" : 1 }