Get the App
SLTechnology News&Howtos  ›  Database  › 

3.5-MongoDB replica set test

Shulou Source: shulou.com Published: 2022-06-01 18:27:40 09月23日 Update

* MongoDB replica set test

Build libraries and collections on the Lord

> use mydb # build a library

> db.acc.insert ({AccountID:1,UserName: "123", password: "123456"}) # insert data

> show dbs # View the library

View from above

> show dbs

If there is an error Error: listDatabases failed: {"note": "from execCommand", "ok": 0, "errmsg": "not master"}, you need to execute

> rs.slaveok ()

* change the weight of MongoDB replica set to simulate the main downtime

By default, the weights of the three machines are all 1. If any one of them is set to a higher weight than the others, the machine will immediately switch to the primary role, so we preset the weights of the three machines as follows: 111vis3, 112, 112, 2 and 101, respectively.

Execute on the Lord

Cfg = rs.conf () # reassign

Cfg.members [0] .priority = 3

Cfg.members [1] .priority = 2

Cfg.members [2] .priority = 1

Rs.reconfig (cfg) # reload

In that case, the second node will be the candidate primary node.

Execute iptables-I INPUT-p tcp-- dport 27017-j DROP on the host

Disadvantages: mongodb can automatically switch between master and slave, but the client cannot automatically switch to the new master. You need to switch manually.

When the original master goes down, the data written by the original master will also be synchronized to the new master before the new master is restored.

Tags: Weight switch machine replica data three sets test in this case master-slave original master malpractice manual user client node role error immediately don't Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology NVidia Xiaomi Microsoft