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

3.5-MongoDB replica set test

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

* 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.

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