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 build Master-Slave replication in MongoDB

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

How to build master-slave replication in MongoDB? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

There are three main ways to build mongodb cluster: master-slave mode, replica set mode and sharding mode.

Master-slave replication

A master node, multiple slave nodes, all slave nodes will go to the master node to get the latest data, so that the master-slave data is consistent.

Disadvantages:

When the master node fails, the slave node will not automatically switch to the master node, which will affect the normal use of the corresponding business, so it is necessary to manually use one of the slave nodes as the master node.

Support:

Master-slave replication is no longer supported after mongodb4.0. The following error will be reported when the database is started after the master-slave parameters are configured in versions above mongodb4.0:

Master/slave replication is no longer supported

You can also familiarize yourself with the building process:

192.168.2.222 Primary Node

192.168.2.187 slave node

Among them, the master library 2.222 has completed the installation of "one: MongoDB installation" in the previous chapter, and the slave library 2.187 needs to install MongoDB in the same way.

After the master-slave node installs MongoDB, you need to configure mongodb.conf

Main library:

[root@cjcos ~] # vim / usr/local/mongodb/conf/mongodb.conf

Add

Master = true

From the library:

[root@rac1 ~] # vim / usr/local/mongodb/conf/mongodb.conf

Add:

Slave = true

Source = 192.168.2.222purl 27017

The master and slave database stops the database

> use admin

Switched to db admin

> db.shutdownServer ()

Start the database from the master-slave library:

Main library:

[root@cjcos] # mongod-- config / usr/local/mongodb/conf/mongodb.conf

Slave library

[root@rac1] # mongod-- config / usr/local/mongodb/conf/mongodb.conf

After reading the above, have you mastered how to build master-slave replication in MongoDB? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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