您好,登錄后才能下訂單哦!
小編給大家分享一下MongoDB副本集如何添加和刪除仲裁節(jié)點(diǎn),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
MongoDB仲裁者(Arbiter)是復(fù)制集中的一個(gè)mongodb實(shí)例,它并不保存數(shù)據(jù)。
仲裁節(jié)點(diǎn)使用最小的資源并且不要求硬件設(shè)備,最好不要將Arbiter部署在同一個(gè)數(shù)據(jù)集節(jié)點(diǎn)中,可以部署在其他服務(wù)器中,也可部署在單獨(dú)的虛擬機(jī)中。
當(dāng)節(jié)點(diǎn)數(shù)目為奇數(shù)時(shí),可以不需要仲裁節(jié)點(diǎn)。
當(dāng)節(jié)點(diǎn)數(shù)目為偶數(shù)個(gè)時(shí),需要部署一個(gè)仲裁節(jié)點(diǎn),否則偶數(shù)個(gè)節(jié)點(diǎn),當(dāng)主節(jié)點(diǎn)掛了后,其他節(jié)點(diǎn)會(huì)變?yōu)橹蛔x。
副本集添加仲裁節(jié)點(diǎn)步驟(本例中MongoDB副本集是一主兩從):
添加仲裁節(jié)點(diǎn):
在仲裁節(jié)點(diǎn)編輯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 (應(yīng)和副本集其他節(jié)點(diǎn)的集群名字保持一致)
啟動(dòng)arbiter上的mongodb實(shí)例:
#/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
登陸到副本集上的主節(jié)點(diǎn),進(jìn)行如下操作:
test:PRIMARY> rs.addArb("192.168.0.3:27019");
{ "ok" : 1 }
查看狀態(tài):
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
}
刪除仲裁節(jié)點(diǎn)方法:
test:PRIMARY> rs.remove("192.168.0.3:27019");
以上是“MongoDB副本集如何添加和刪除仲裁節(jié)點(diǎn)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。