Get the App
SLTechnology News&Howtos  ›  Database  › 

Mongodb master-slave configuration

Shulou Source: shulou.com Published: 2022-06-01 13:28:26 09月30日 Update

1. Mongodb master-slave configuration

The master and slave are all on the same server, the master is the default port, and the slave is 9999

1) master

/ usr/local/mongodb/bin/mongod-master-dbpath / usr/local/mongodb/data/-logpath / usr/local/mongodb/log/mongodb.log-directoryperdb &

2) slave

/ web/mongodb/bin/mongod-- slave-- source 192.168.103.217 source 27017-- dbpath / web/mongodb/data/-- logpath / web/mongodb/log/mongo.log-- directoryperdb &

2. Mutual principal and subordinate

1) master

/ usr/local/mongodb/bin/mongod-- master-- slave-- source 192.168.103.217 purl 9999-- dbpath / usr/local/mongodb/data/-- logpath / usr/local/mongodb/log/mongodb.log-- directoryperdb &

2) slave

/ web/mongodb/bin/mongod-- port 9999-- master-- slave-- source 192.168.103.217 master-- dbpath / web/mongodb/data/-- logpath / web/mongodb/log/mongo.log-- directoryperdb &

3. Master and slave with authentication

1) master

Add user root,local Library to admin Library add user repl

Use admin

Db.addUser ('root','123')

Db.auth ('root','123')

Use local

Db.addUser ('repl','123')

Db.auth ('repl','123')

/ usr/local/mongodb/bin/mongod-master-auth-dbpath / usr/local/mongodb/data/-logpath / usr/local/mongodb/log/mongodb.log-directoryperdb &

2) slave

Add user root,local Library to admin Library add user repl

Use admin

Db.addUser ('root','123')

Db.auth ('root','123')

Use local

Db.addUser ('repl','123')

Db.auth ('repl','123')

/ web/mongodb/bin/mongod-- port 9999-- slave-- source 192.168.103.217 slave-- auth-- dbpath / web/mongodb/data/-- logpath / web/mongodb/log/mongo.log-- directoryperdb &

4. Test

If master and slave, write on master to see if you can synchronize to slave library.

If you are the master and slave of each other, you will write data on two databases to see if they can be synchronized to another database.

Tags: Master-slave user data database synchronization configuration two server port service test authentication Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Docker vpn Linux