MongoDB 删除,添加副本集,并修改副本集IP等信息
添加副本,在登录到主节点下输入
rs.add("ip:port");
删除副本
rs.remove("ip:port");
新增仲裁节点
rs.addArb("ip:port");
修改副本host:
1shard1:PRIMARY> cfg = rs.conf() 2{ 3 "_id" : "shard1", 4 "version" : 5, 5 "protocolVersion" : NumberLong(1), 6 "members" : [ 7 { 8 "_id" : 0, 9 "host" : "127.0.0.1:2777", 10 "arbiterOnly" : false, 11 "buildIndexes" : true, 12 "hidden" : false, 13 "priority" : 1, 14 "tags" : { 15 16 }, 17 "slaveDelay" : NumberLong(0), 18 "votes" : 1 19 } 20 ], 21 "settings" : { 22 "chainingAllowed" : true, 23 "heartbeatIntervalMillis" : 2000, 24 "heartbeatTimeoutSecs" : 10, 25 "electionTimeoutMillis" : 10000, 26 "getLastErrorModes" : { 27 28 }, 29 "getLastErrorDefaults" : { 30 "w" : 1, 31 "wtimeout" : 0 32 }, 33 "replicaSetId" : ObjectId("5d9c7a7e76695600e03e231f") 34 } 35} 36 37 38shard1:PRIMARY> cfg.members[0].host = "10.13.10.2:2777" 3910.130.10.72:2777 40shard1:PRIMARY> rs.reconfig(cfg) 41{ "ok" : 1 } 42shard1:PRIMARY> rs.status() 43{ 44 "set" : "shard1", 45 "date" : ISODate("2019-10-09T02:59:26.916Z"), 46 "myState" : 1, 47 "term" : NumberLong(1), 48 "heartbeatIntervalMillis" : NumberLong(2000), 49 "members" : [ 50 { 51 "_id" : 0, 52 "name" : "10.130.10.72:2777", 53 "health" : 1, 54 "state" : 1, 55 "stateStr" : "PRIMARY", 56 "uptime" : 54711, 57 "optime" : { 58 "ts" : Timestamp(1570589961, 1), 59 "t" : NumberLong(1) 60 }, 61 "optimeDate" : ISODate("2019-10-09T02:59:21Z"), 62 "electionTime" : Timestamp(1570536062, 2), 63 "electionDate" : ISODate("2019-10-08T12:01:02Z"), 64 "configVersion" : 6, 65 "self" : true 66 } 67 ], 68 "ok" : 1 69}