Get the App
SLTechnology News&Howtos  ›  Database  › 

How to build Master-Slave replication in MongoDB

Shulou Source: shulou.com Published: 2022-05-31 21:16:05 09月18日 Update

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!

Tags: Node master-slave data database method pattern content more problem support configuration consistency helplessness for this business human copy reason parameter multiple Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Huawei OPPO Reno Apple Shulou Technology