全部博文(150)
分类: NOSQL
2017-08-17 10:49:18
拥有4个节点(1primary 3secondary)的复制集理论上如果有任意一个节点宕机,均可保证集群选举出新的primary,保证集群的可用性。只是当前状态数据要保持4份,从磁盘空间利用率的角度来看不够节约,于是计划调整为1primary、2secondary、1ARBITER的模式。
查看集群状态
goluk:PRIMARY> rs.status() { "set" : "goluk", "date" : ISODate("2017-08-17T02:18:15.981Z"), "myState" : 1, "term" : NumberLong(-1), "heartbeatIntervalMillis" : NumberLong(2000), "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1502936295, 493), "t" : NumberLong(-1) }, "appliedOpTime" : Timestamp(1502936295, 493), "durableOpTime" : Timestamp(1502936295, 481) }, "members" : [ { "_id" : 0, "name" : "10.0.1.31:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 8479476, "optime" : Timestamp(1502936295, 493), "optimeDate" : ISODate("2017-08-17T02:18:15Z"), "electionTime" : Timestamp(1502896073, 1), "electionDate" : ISODate("2017-08-16T15:07:53Z"), "configVersion" : 10, "self" : true }, { "_id" : 1, "name" : "10.0.1.32:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 40222, "optime" : Timestamp(1502936294, 239), "optimeDurable" : Timestamp(1502936294, 239), "optimeDate" : ISODate("2017-08-17T02:18:14Z"), "optimeDurableDate" : ISODate("2017-08-17T02:18:14Z"), "lastHeartbeat" : ISODate("2017-08-17T02:18:14.589Z"), "lastHeartbeatRecv" : ISODate("2017-08-17T02:18:15.485Z"), "pingMs" : NumberLong(0), "syncingTo" : "10.0.1.33:27017", "configVersion" : 10 }, { "_id" : 2, "name" : "192.168.1.230:27017", "health" : 0, "state" : 8, "stateStr" : "(not reachable/healthy)", "uptime" : 0, "optime" : Timestamp(0, 0), "optimeDurable" : Timestamp(0, 0), "optimeDate" : ISODate("1970-01-01T00:00:00Z"), "optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"), "lastHeartbeat" : ISODate("2017-08-17T02:18:14.515Z"), "lastHeartbeatRecv" : ISODate("2017-07-15T14:54:07.533Z"), "pingMs" : NumberLong(31), "lastHeartbeatMessage" : "Connection refused", "configVersion" : -1 }, { "_id" : 3, "name" : "10.0.1.33:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 2801929, "optime" : Timestamp(1502936295, 338), "optimeDurable" : Timestamp(1502936295, 337), "optimeDate" : ISODate("2017-08-17T02:18:15Z"), "optimeDurableDate" : ISODate("2017-08-17T02:18:15Z"), "lastHeartbeat" : ISODate("2017-08-17T02:18:15.421Z"), "lastHeartbeatRecv" : ISODate("2017-08-17T02:18:14.407Z"), "pingMs" : NumberLong(0), "syncingTo" : "10.0.1.31:27017", "configVersion" : 10 } ], "ok" : 1 }
移除230节点
goluk:PRIMARY> rs.remove("192.168.1.230:27017") { "ok" : 1 }
移除之后查看集群状态
goluk:PRIMARY> rs.status() { "set" : "goluk", "date" : ISODate("2017-08-17T02:20:03.647Z"), "myState" : 1, "term" : NumberLong(-1), "heartbeatIntervalMillis" : NumberLong(2000), "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1502936403, 86), "t" : NumberLong(-1) }, "appliedOpTime" : Timestamp(1502936403, 292), "durableOpTime" : Timestamp(1502936403, 150) }, "members" : [ { "_id" : 0, "name" : "10.0.1.31:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 8479584, "optime" : Timestamp(1502936403, 292), "optimeDate" : ISODate("2017-08-17T02:20:03Z"), "electionTime" : Timestamp(1502896073, 1), "electionDate" : ISODate("2017-08-16T15:07:53Z"), "configVersion" : 11, "self" : true }, { "_id" : 1, "name" : "10.0.1.32:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 40330, "optime" : Timestamp(1502936401, 721), "optimeDurable" : Timestamp(1502936401, 720), "optimeDate" : ISODate("2017-08-17T02:20:01Z"), "optimeDurableDate" : ISODate("2017-08-17T02:20:01Z"), "lastHeartbeat" : ISODate("2017-08-17T02:20:01.725Z"), "lastHeartbeatRecv" : ISODate("2017-08-17T02:20:01.726Z"), "pingMs" : NumberLong(0), "syncingTo" : "10.0.1.33:27017", "configVersion" : 11 }, { "_id" : 3, "name" : "10.0.1.33:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 2802036, "optime" : Timestamp(1502936401, 721), "optimeDurable" : Timestamp(1502936401, 721), "optimeDate" : ISODate("2017-08-17T02:20:01Z"), "optimeDurableDate" : ISODate("2017-08-17T02:20:01Z"), "lastHeartbeat" : ISODate("2017-08-17T02:20:01.725Z"), "lastHeartbeatRecv" : ISODate("2017-08-17T02:20:01.764Z"), "pingMs" : NumberLong(0), "syncingTo" : "10.0.1.31:27017", "configVersion" : 11 } ], "ok" : 1
增加仲裁节点
goluk:PRIMARY> rs.addArb("192.168.1.230:27017") { "ok" : 1 }
查看集群状态,确认仲裁节点
goluk:PRIMARY> rs.status() { "set" : "goluk", "date" : ISODate("2017-08-17T02:28:10.300Z"), "myState" : 1, "term" : NumberLong(-1), "heartbeatIntervalMillis" : NumberLong(2000), "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1502936890, 59), "t" : NumberLong(-1) }, "appliedOpTime" : Timestamp(1502936890, 60), "durableOpTime" : Timestamp(1502936890, 36) }, "members" : [ { "_id" : 0, "name" : "10.0.1.31:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 8480071, "optime" : Timestamp(1502936890, 60), "optimeDate" : ISODate("2017-08-17T02:28:10Z"), "electionTime" : Timestamp(1502896073, 1), "electionDate" : ISODate("2017-08-16T15:07:53Z"), "configVersion" : 12, "self" : true }, { "_id" : 1, "name" : "10.0.1.32:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 40817, "optime" : Timestamp(1502936889, 662), "optimeDurable" : Timestamp(1502936889, 662), "optimeDate" : ISODate("2017-08-17T02:28:09Z"), "optimeDurableDate" : ISODate("2017-08-17T02:28:09Z"), "lastHeartbeat" : ISODate("2017-08-17T02:28:09.915Z"), "lastHeartbeatRecv" : ISODate("2017-08-17T02:28:09.981Z"), "pingMs" : NumberLong(0), "syncingTo" : "10.0.1.33:27017", "configVersion" : 12 }, { "_id" : 3, "name" : "10.0.1.33:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 2802523, "optime" : Timestamp(1502936889, 662), "optimeDurable" : Timestamp(1502936889, 662), "optimeDate" : ISODate("2017-08-17T02:28:09Z"), "optimeDurableDate" : ISODate("2017-08-17T02:28:09Z"), "lastHeartbeat" : ISODate("2017-08-17T02:28:09.916Z"), "lastHeartbeatRecv" : ISODate("2017-08-17T02:28:09.978Z"), "pingMs" : NumberLong(0), "syncingTo" : "10.0.1.31:27017", "configVersion" : 12 }, { "_id" : 4, "name" : "192.168.1.230:27017", "health" : 1, "state" : 7, "stateStr" : "ARBITER", "uptime" : 10, "lastHeartbeat" : ISODate("2017-08-17T02:28:10.170Z"), "lastHeartbeatRecv" : ISODate("2017-08-17T02:28:08.512Z"), "pingMs" : NumberLong(31), "configVersion" : 12 } ], "ok" : 1 }
在230上节点上继续确认是否更改为仲裁节点
goluk:ARBITER>