Get the App
SLTechnology News&Howtos  ›  Database  › 

How to realize Master-Slave replication of Mmurs in MongoDB Database

Shulou Source: shulou.com Published: 2022-05-31 21:11:40 10月28日 Update

This article shows you how to achieve MongoDB database master-slave replication, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

[root@localhost ~] # mkdir / data/db/master

[root@localhost ~] # mkdir / data/db/slave

Master: just take the-master parameter to show that it is a master, which is quite convenient.

[root@localhost] # / usr/local/bin/mongod-- master

-dbpath=/data/db/master-port=11536 &

[1] 10939

[root@localhost ~] # Mon

Jul 25 20:21:59 [initandlisten] MongoDB

Starting: pid=10939 port=11536 dbpath=/data/db/master

Master=1 32-bit

From: with-- slave parameter indicates that it is a slave, specify-- source, the address and port of the master, which is much more convenient than MYSQL.

[root@localhost bin] # / usr/local/bin/mongod-port

11537-slave-dbpath=/data/db/slave-source 127.0.0.1 source 11536

Mon Jul 25 20:25:52 [initandlisten] MongoDB

Starting: pid=11158 port=11537 dbpath=/data/db/slave

Slave=1 32-bit

Open a new terminal, log in to 11536 (master), and write a record

[root@localhost] # / usr/local/bin/mongo-- port=11536

MongoDB shell version: 1.8.2

Connecting to: 127.0.0.1:11536/test

> use brucezuo

Switched to db brucezuo

> db.createCollection ("table1")

{"ok": 1}

> db.table1.insert ({id:1,name: "zxy", age:29})

>

Open a new terminal, log in to 11537 (from), and check whether the data is consistent.

[root@localhost] # / usr/local/bin/mongo-- port=11537

MongoDB shell version: 1.8.2

Connecting to: 127.0.0.1:11537/test

> show dbs

Admin (empty)

Brucezuo 0.0625GB

Local 0.0625GB

> use brucezuo

Switched to db brucezuo

> db.table1.find ()

{"_ id": ObjectId ("4e2e348ed502dbae1aee469e"), "id": 1, "name": "zxy", "age": 29}

>

The above content is how to achieve master-slave replication in MongoDB database. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Data master and slave database content parameters skills knowledge terminal new login concise consistent concise address that is articles more ports articles industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Technology Huawei Apple MariaDB