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");
仲裁節點使用最小的資源並且不要求硬體裝置,最好不要將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");
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2151331/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MongoDB 4.2副本集新增/刪除副本(一主一副一仲裁)MongoDB
- mongodb副本集新增刪除節點MongoDB
- 【Mongodb】 replica set 新增和刪除節點。MongoDB
- MongoDB 刪除,新增副本集,並修改副本集IP等資訊MongoDB
- MongoDB 4.2副本集自動故障轉移(一主一副一仲裁)MongoDB
- MongoDB副本集節點的優先值修改一例MongoDB
- mongodb主從仲裁節點配置MongoDB
- MongoDB叢集搭建(包括隱藏節點,仲裁節點)MongoDB
- mongodb 4.0副本集搭建MongoDB
- MongoDB 6.0.3副本集搭建MongoDB
- Hyperledger Fabric節點的動態新增和刪除
- 新增和刪除hadoop叢集中的節點Hadoop
- redis cluster節點/新增刪除操作Redis
- networkx基礎用法:新增節點、新增邊、刪除節點、刪除邊、計算度、賦權重
- k8s叢集刪除和新增node節點K8S
- oracle11g_RAC新增刪除節點Oracle
- Oracle叢集軟體管理-新增和刪除叢集節點Oracle
- oracle 10g rac,刪除故障節點並新增新節點Oracle 10g
- oracle 10g rac 新增節點與刪除節點步驟Oracle 10g
- Mongodb3.0.5副本集搭建及spring和java連線副本集配置MongoDBSpringJava
- MongoDB日常運維-04副本集搭建MongoDB運維
- Hadoop增加和刪除節點Hadoop
- mongodb副本集用一致性快照方法新增從節點步驟MongoDB
- 11G R2 RAC新增刪除節點
- 單機Linux下搭建MongoDB副本集-三節點LinuxMongoDB
- MongoDB日常運維-05副本集故障切換MongoDB運維
- JavaScript刪除節點自身JavaScript
- Oracle Rac 刪除節點Oracle
- MongoDB副本集(一主一備+仲裁)環境部署-運維操作記錄MongoDB運維
- 2.MongoDB 4.2副本集環境基於時間點的恢復MongoDB
- 【RAC】Oracle10g rac新增刪除節點命令參考Oracle
- 怎樣新增、刪除、移動、複製、建立、查詢節點
- jQuery如何刪除元素節點jQuery
- DOM節點刪除之empty和remove區別REM
- onnx 增刪改查,修改節點,刪除節點,修改input,output
- jQuery 新增和刪除classjQuery
- Solr 刪除和新增 indexSolrIndex
- 【RAC】刪除RAC資料庫節點(二)——刪除ASM資料庫ASM