In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.