Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add and remove quorum nodes from a MongoDB replica set

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to add and delete MongoDB copy set arbitration nodes, I believe that most people do not understand, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

The MongoDB arbitrator (Arbiter) is an instance of mongodb in the replication set that does not hold data.

Quorum nodes use minimal resources and do not require hardware, so it is best not to deploy Arbiter in the same dataset node, either on other servers or in separate virtual machines.

When the number of nodes is odd, there is no need for arbitration nodes.

When the number of nodes is even, you need to deploy a quorum node, otherwise an even number of nodes, when the primary node dies, the other nodes will become read-only.

Step to add a quorum node to the replica set (in this case, the MongoDB replica set is one master and two slaves):

Add a quorum node:

Edit mongodb.conf in the quorum node

# vi / etc/mongodb.conf

Logpath=/home/mongodb/logs/arbiter.log

Logappend=false

Port=27019

Fork=true

Dbpath=/home/mongodb/arbiter

# auth=true

ReplSet=test (should be consistent with the cluster names of other nodes in the replica set)

Start the mongodb instance on arbiter:

# / 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

Log in to the master node on the replica set and do the following:

Test:PRIMARY > rs.addArb ("192.168.0.3 virtual 27019")

{"ok": 1}

View status:

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 purl 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 purl 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 purl 27017"

"configVersion": 4

}

{

"_ id": 2

"name": "192.168.0.61 purl 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 purl 27017"

"configVersion": 4

}

{

"_ id": 3

"name": "192.168.0.3 virtual 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 purl 27017"

"192.168.0.52purl 27017"

"192.168.0.61 purl 27017"

]

"arbiters": [

"192.168.0.3 Flux 27019"

]

"setName": "test"

"setVersion": 4

"ismaster": true

"secondary": false

"primary": "192.168.0.51 purl 27017"

"me": "192.168.0.51 purl 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

}

Delete the quorum node method:

Test:PRIMARY > rs.remove ("192.168.0.3 virtual 27019")

The above is all the content of the article "how to add and remove arbitration nodes from MongoDB replica set". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report