mongodb添加arbiter节点的方法示例
程序员文章站
2022-06-25 09:46:42
前言
在创建mongodb的replica set的时候,只是做成了1主2从,没有做成1主1从1仲裁。这我们将一个几点从replica set中删除,再以仲裁节点的身份加...
前言
在创建mongodb的replica set的时候,只是做成了1主2从,没有做成1主1从1仲裁。这我们将一个几点从replica set中删除,再以仲裁节点的身份加入到replica set中:
1.初始状态:
shard1replset:primary> rs.status();rs.status(); { "set" : "shard1replset", "date" : isodate("2017-02-21t07:48:03.058z"), "mystate" : 1, "term" : numberlong(1), "heartbeatintervalmillis" : numberlong(2000), "optimes" : { "lastcommittedoptime" : { "ts" : timestamp(0, 0), "t" : numberlong(-1) }, "appliedoptime" : { "ts" : timestamp(1487663274, 1), "t" : numberlong(1) }, "durableoptime" : { "ts" : timestamp(1487587982, 1), "t" : numberlong(-1) } }, "members" : [ { "_id" : 0, "name" : "10.13.0.130:22001", "health" : 1, "state" : 1, "statestr" : "primary", "uptime" : 76672, "optime" : { "ts" : timestamp(1487663274, 1), "t" : numberlong(1) }, "optimedate" : isodate("2017-02-21t07:47:54z"), "electiontime" : timestamp(1487587993, 1), "electiondate" : isodate("2017-02-20t10:53:13z"), "configversion" : 1, "self" : true }, { "_id" : 1, "name" : "10.13.0.131:22001", "health" : 1, "state" : 2, "statestr" : "secondary", "uptime" : 75300, "optime" : { "ts" : timestamp(1487663274, 1), "t" : numberlong(1) }, "optimedurable" : { "ts" : timestamp(1487587982, 1), "t" : numberlong(-1) }, "optimedate" : isodate("2017-02-21t07:47:54z"), "optimedurabledate" : isodate("2017-02-20t10:53:02z"), "lastheartbeat" : isodate("2017-02-21t07:48:02.150z"), "lastheartbeatrecv" : isodate("2017-02-21t07:48:02.215z"), "pingms" : numberlong(0), "syncingto" : "10.13.0.132:22001", "configversion" : 1 }, { "_id" : 2, "name" : "10.13.0.132:22001", "health" : 1, "state" : 2, "statestr" : "secondary", "uptime" : 75300, "optime" : { "ts" : timestamp(1487663274, 1), "t" : numberlong(1) }, "optimedurable" : { "ts" : timestamp(1487587982, 1), "t" : numberlong(-1) }, "optimedate" : isodate("2017-02-21t07:47:54z"), "optimedurabledate" : isodate("2017-02-20t10:53:02z"), "lastheartbeat" : isodate("2017-02-21t07:48:02.889z"), "lastheartbeatrecv" : isodate("2017-02-21t07:48:01.503z"), "pingms" : numberlong(0), "syncingto" : "10.13.0.130:22001", "configversion" : 1 } ], "ok" : 1 } shard1replset:primary> shard1replset:primary> shard1replset:primary> shard1replset:primary>
2.删除节点:
shard1replset:primary> rs.remove("10.13.0.132:22001"); rs.remove("10.13.0.132:22001"); { "ok" : 1 } shard1replset:primary> rs.status();rs.status(); { "set" : "shard1replset", "date" : isodate("2017-02-21t07:50:52.934z"), "mystate" : 1, "term" : numberlong(1), "heartbeatintervalmillis" : numberlong(2000), "optimes" : { "lastcommittedoptime" : { "ts" : timestamp(0, 0), "t" : numberlong(-1) }, "appliedoptime" : { "ts" : timestamp(1487663447, 1), "t" : numberlong(1) }, "durableoptime" : { "ts" : timestamp(1487587982, 1), "t" : numberlong(-1) } }, "members" : [ { "_id" : 0, "name" : "10.13.0.130:22001", "health" : 1, "state" : 1, "statestr" : "primary", "uptime" : 76841, "optime" : { "ts" : timestamp(1487663447, 1), "t" : numberlong(1) }, "optimedate" : isodate("2017-02-21t07:50:47z"), "electiontime" : timestamp(1487587993, 1), "electiondate" : isodate("2017-02-20t10:53:13z"), "configversion" : 2, "self" : true }, { "_id" : 1, "name" : "10.13.0.131:22001", "health" : 1, "state" : 2, "statestr" : "secondary", "uptime" : 75470, "optime" : { "ts" : timestamp(1487663447, 1), "t" : numberlong(1) }, "optimedurable" : { "ts" : timestamp(1487587982, 1), "t" : numberlong(-1) }, "optimedate" : isodate("2017-02-21t07:50:47z"), "optimedurabledate" : isodate("2017-02-20t10:53:02z"), "lastheartbeat" : isodate("2017-02-21t07:50:51.182z"), "lastheartbeatrecv" : isodate("2017-02-21t07:50:52.212z"), "pingms" : numberlong(0), "configversion" : 2 } ], "ok" : 1 } shard1replset:primary> shard1replset:primary> shard1replset:primary>
3.添加成arbiter节点:
shard1replset:primary> rs.addarb("10.13.0.132:22001");rs.addarb("10.13.0.132:22001"); { "ok" : 1 } shard1replset:primary> shard1replset:primary> rs.status();rs.status(); { "set" : "shard1replset", "date" : isodate("2017-02-21t07:54:05.161z"), "mystate" : 1, "term" : numberlong(1), "heartbeatintervalmillis" : numberlong(2000), "optimes" : { "lastcommittedoptime" : { "ts" : timestamp(0, 0), "t" : numberlong(-1) }, "appliedoptime" : { "ts" : timestamp(1487663637, 1), "t" : numberlong(1) }, "durableoptime" : { "ts" : timestamp(1487587982, 1), "t" : numberlong(-1) } }, "members" : [ { "_id" : 0, "name" : "10.13.0.130:22001", "health" : 1, "state" : 1, "statestr" : "primary", "uptime" : 77034, "optime" : { "ts" : timestamp(1487663637, 1), "t" : numberlong(1) }, "optimedate" : isodate("2017-02-21t07:53:57z"), "electiontime" : timestamp(1487587993, 1), "electiondate" : isodate("2017-02-20t10:53:13z"), "configversion" : 3, "self" : true }, { "_id" : 1, "name" : "10.13.0.131:22001", "health" : 1, "state" : 2, "statestr" : "secondary", "uptime" : 75662, "optime" : { "ts" : timestamp(1487663637, 1), "t" : numberlong(1) }, "optimedurable" : { "ts" : timestamp(1487587982, 1), "t" : numberlong(-1) }, "optimedate" : isodate("2017-02-21t07:53:57z"), "optimedurabledate" : isodate("2017-02-20t10:53:02z"), "lastheartbeat" : isodate("2017-02-21t07:54:03.210z"), "lastheartbeatrecv" : isodate("2017-02-21t07:54:02.211z"), "pingms" : numberlong(0), "configversion" : 3 }, { "_id" : 2, "name" : "10.13.0.132:22001", "health" : 1, "state" : 7, "statestr" : "arbiter", "uptime" : 5, "lastheartbeat" : isodate("2017-02-21t07:54:03.214z"), "lastheartbeatrecv" : isodate("2017-02-21t07:54:02.274z"), "pingms" : numberlong(0), "configversion" : 3 } ], "ok" : 1 } shard1replset:primary>
注1: mongodb 3.4之后,虽然要求config server为replica set,但是不支持arbiter。
添加的时候,会报错:
cfgreplset:primary> rs.addarb("10.13.0.132:21000");rs.addarb("10.13.0.132:21000"); { "ok" : 0, "errmsg" : "arbiters are not allowed in replica set configurations being used for config servers", "code" : 103, "codename" : "newreplicasetconfigurationincompatible" } cfgreplset:primary>
注2:rs.reconfig()也可以进行操作,效果类似re.remove+rs.addarb,详见:mongodb官方文档- remove members from replica set
总结
以上就是关于mongodb添加arbiter节点的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。
上一篇: 山里信号不好