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

Principle of mongodb replica set

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

Share

Shulou(Shulou.com)06/02 Report--

1. Principle:

The replica cluster sends a heartbeat every 2 seconds and is marked as unreachable if it is not received after 10 seconds.

MongoDB applies the database operation on the primary database and then records the operation in the operation log of the primary database. The auxiliary member then copies and applies these operations to the asynchronous process. All replica set members contain a copy of the operation log in the local.oplog.rs collection, with a default size of 5% of the disk, but no query operations are recorded. OplogSize can specify the size in / etc/mongdb.conf

Replication: oplogSizeMB: replSetName: secondaryIndexPrefetch: enableMajorityReadConcern:

Member roles in the 2.mongdb replica set:

Primary: responsible for writing data

Seconary: responsible for synchronizing data on the master and providing read service

Arbitration node: do not keep data, do not participate in the election, only carry out the election.

The replica set is elected as a priority, and the range 0-1000 minute 0 is the arbitration node and does not participate in the election. The default is 1

3. How to set it up?

MongoDB Enterprise shard-rs:PRIMARY > config=rs.conf () MongoDB Enterprise shard-rs:PRIMARY > config {"_ id": "shard-rs", "version": 3, "protocolVersion": NumberLong (1), "writeConcernMajorityJournalDefault": true, "members": [{"_ id": 0 "host": "worker2:27020", "arbiterOnly": false, "buildIndexes": true, "hidden": false, "priority": 1 "tags": {}, "slaveDelay": NumberLong (0), "votes": 1}, {"_ id": 1 "host": "worker2:27021", "arbiterOnly": false, "buildIndexes": true, "hidden": false, "priority": 1 "tags": {}, "slaveDelay": NumberLong (0), "votes": 1}, {"_ id": 2 "host": "worker2:27022", "arbiterOnly": false, "buildIndexes": true, "hidden": false, "priority": 1 "tags": {}, "slaveDelay": NumberLong (0), "votes": 1}], "settings": {"chainingAllowed": true, "heartbeatIntervalMillis": 2000 "heartbeatTimeoutSecs": 10, "electionTimeoutMillis": 10000, "catchUpTimeoutMillis":-1, "catchUpTakeoverDelayMillis": 30000, "getLastErrorModes": {}, "getLastErrorDefaults": {"w": 1 "wtimeout": 0}, "replicaSetId": ObjectId ("5dd8bf958b8ea486b84c23b2")}}

The priority of a fragment with an id value of 2 is changed to 3. When primary, a fragment with an id value of 2 becomes prmary.

Config.members [2] .priority = 3

Deliberately stop the 27020 process.

Kill-9 82609

Check whether a host with an id value of 2 becomes a primary

Enter the mongdb of 27022:

MongoDB Enterprise shard-rs:PRIMARY > use adminswitched to db adminMongoDB Enterprise shard-rs:PRIMARY > db.isMaster () {"hosts": ["worker2:27020", "worker2:27021", "worker2:27022"], "setName": "shard-rs", "setVersion": 4, "ismaster": true # become primary "secondary": false

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

Servers

Wechat

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

12
Report