千家信息网

MongoDB副本集如何添加和删除仲裁节点

发表于:2024-11-30 作者:千家信息网编辑
千家信息网最后更新 2024年11月30日,小编给大家分享一下MongoDB副本集如何添加和删除仲裁节点,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!MongoDB仲
千家信息网最后更新 2024年11月30日MongoDB副本集如何添加和删除仲裁节点

小编给大家分享一下MongoDB副本集如何添加和删除仲裁节点,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

MongoDB仲裁者(Arbiter)是复制集中的一个mongodb实例,它并不保存数据。
仲裁节点使用最小的资源并且不要求硬件设备,最好不要将Arbiter部署在同一个数据集节点中,可以部署在其他服务器中,也可部署在单独的虚拟机中。

当节点数目为奇数时,可以不需要仲裁节点。
当节点数目为偶数个时,需要部署一个仲裁节点,否则偶数个节点,当主节点挂了后,其他节点会变为只读。

副本集添加仲裁节点步骤(本例中MongoDB副本集是一主两从):
添加仲裁节点:
在仲裁节点编辑mongodb.conf
# vi /etc/mongodb.conf
logpath=/home/mongodb/logs/arbiter.log
logappend=false
port=27019
fork=true
dbpath=/home/mongodb/arbiter
#auth=true
replSet=test (应和副本集其他节点的集群名字保持一致)

启动arbiter上的mongodb实例:
#/data/mongodb-3.4.13/bin/mongod -f /etc/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 23331
child process started successfully, parent exiting

登陆到副本集上的主节点,进行如下操作:
test:PRIMARY> rs.addArb("192.168.0.3:27019");
{ "ok" : 1 }

查看状态:
test:PRIMARY> rs.status()
{
"set" : "test",
"date" : ISODate("2018-02-27T08:24:28.866Z"),
"myState" : 1,
"term" : NumberLong(6),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1519719858, 1),
"t" : NumberLong(6)
},
"appliedOpTime" : {
"ts" : Timestamp(1519719858, 1),
"t" : NumberLong(6)
},
"durableOpTime" : {
"ts" : Timestamp(1519719858, 1),
"t" : NumberLong(6)
}
},
"members" : [
{
"_id" : 0,
"name" : "192.168.0.51:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 4429,
"optime" : {
"ts" : Timestamp(1519719858, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2018-02-27T08:24:18Z"),
"electionTime" : Timestamp(1519716787, 1),
"electionDate" : ISODate("2018-02-27T07:33:07Z"),
"configVersion" : 4,
"self" : true
},
{
"_id" : 1,
"name" : "192.168.0.52:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 4369,
"optime" : {
"ts" : Timestamp(1519719858, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1519719858, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2018-02-27T08:24:18Z"),
"optimeDurableDate" : ISODate("2018-02-27T08:24:18Z"),
"lastHeartbeat" : ISODate("2018-02-27T08:24:27.265Z"),
"lastHeartbeatRecv" : ISODate("2018-02-27T08:24:28.224Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "192.168.0.51:27017",
"configVersion" : 4
},
{
"_id" : 2,
"name" : "192.168.0.61:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 2501,
"optime" : {
"ts" : Timestamp(1519719858, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1519719858, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2018-02-27T08:24:18Z"),
"optimeDurableDate" : ISODate("2018-02-27T08:24:18Z"),
"lastHeartbeat" : ISODate("2018-02-27T08:24:27.099Z"),
"lastHeartbeatRecv" : ISODate("2018-02-27T08:24:28.024Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "192.168.0.51:27017",
"configVersion" : 4
},
{
"_id" : 3,
"name" : "192.168.0.3:27019",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 96,
"lastHeartbeat" : ISODate("2018-02-27T08:24:28.443Z"),
"lastHeartbeatRecv" : ISODate("2018-02-27T08:24:27.449Z"),
"pingMs" : NumberLong(1),
"configVersion" : 4
}
],
"ok" : 1
}
test:PRIMARY>


test:PRIMARY> db.isMaster()
{
"hosts" : [
"192.168.0.51:27017",
"192.168.0.52:27017",
"192.168.0.61:27017"
],
"arbiters" : [
"192.168.0.3:27019"
],
"setName" : "test",
"setVersion" : 4,
"ismaster" : true,
"secondary" : false,
"primary" : "192.168.0.51:27017",
"me" : "192.168.0.51:27017",
"electionId" : ObjectId("7fffffff0000000000000006"),
"lastWrite" : {
"opTime" : {
"ts" : Timestamp(1519719928, 1),
"t" : NumberLong(6)
},
"lastWriteDate" : ISODate("2018-02-27T08:25:28Z")
},
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 1000,
"localTime" : ISODate("2018-02-27T08:25:33.660Z"),
"maxWireVersion" : 5,
"minWireVersion" : 0,
"readOnly" : false,
"ok" : 1
}

删除仲裁节点方法:
test:PRIMARY> rs.remove("192.168.0.3:27019");

以上是"MongoDB副本集如何添加和删除仲裁节点"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0