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

MongoDB master-slave configuration [2]

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

Share

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

MongoDB master-slave configuration

1. Experimental environment

Master: 192.168.3.206

From: 192.168.3.210

two。 Installation method (execute the following commands in the master and slave respectively)

Groupadd mongodb

Useradd mongodb-g mongodb

Cd / root/soft

Tar-zxvf mongodb-linux-x86_64-2.6.3.tgz

Mv mongodb-linux-x86_64-2.6.3 mongodb

Mv mongodb / usr/local/

Cd / usr/local/

Chown-R mongodb: mongodb mongodb

Cd mongodb

Mkdir-p / data/mongodb

Mkdir-p / data/logs/mongodb/

3. Start the service in master:192.168.3.206

Start command

/ usr/local/mongodb/bin/mongod-master-dbpath=/data/mongodb/-logpath / data/logs/mongodb/log.log-logappend-port=27017-fork

4. Start the service in slave:192.168.3.210

Start command

/ usr/local/mongodb/bin/mongod-- slave-- source 192.168.3.206 source 27017-- dbpath=/data/mongodb/-- logpath / data/logs/mongodb/log.log-- logappend-- port=27017-fork

5. Test master-slave

(1) insert data on the main database

/ usr/local/mongodb/bin/mongo

Use mytest

> db.test03.insert ({age:26})

WriteResult ({"nInserted": 1})

> db.test03.find ()

{"_ id": ObjectId ("53c4f9dd7f7a3afaa3dd2415"), "age": 26}

(2) View the data on the slave (there is already data inserted on the master, indicating that the master and slave are successful)

/ usr/local/mongodb/bin/mongo

Use mytest

> db.test03.find ()

{"_ id": ObjectId ("53c4f9dd7f7a3afaa3dd2415"), "age": 26

Note: the main library test01 collection inserts a record, which depends on whether there is a record at this time. If there is a description of master-slave synchronization OK.

6. Emergency response

What if the master dies in the application?

In this case, it is necessary to stop the slave library and start the slave library with the startup command of the master library.

(1) stop the slave library

Kill-9 process number

(2) Delete files under locat

Rm-rf / data/logs/mongodb/locat.*

(3) start the slave library

/ usr/local/mongodb/bin/mongod-master-dbpath=/data/mongodb/-logpath / data/logs/mongodb/log.log-logappend-port=27017-fork

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