In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, the editor will bring you about how to manage replica sets in MongoDB. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1) diagnosis
A machine in a set of copies can use the
> db.printReplicationInfo ()
View the status of replication for the primary database.
Use
> db.printSlaveReplicationInfo ()
To check the status of replication from the database, you can check whether there is replication delay between the master and slave
2) oplog sets and changes the oplog size
Full synchronization, very time-consuming, manually resynchronize using commands:
> db.runCommand ({"resync": 1})
Use the-- oplogSize parameter to set a larger oplog size.
Assuming that the MongoDB data directory is / data/db, use the command after shutting down the mongod service on the primary node:
> rm / data/db/local.*
> mongod-oplog=8038-master
The parameter noprealloc is used when starting MongoDB to turn off space pre-allocation.
For example, to generate the filespace for 20GB, use the command:
Cd / tmp/local
For i in {0..9}
Do
Echo $I
Head-c 2146435072 / dev/zero > local.$i
Done
Then close the MongoDB master node to move the data file
Mv / data/db/local.* / safe/data
Mv / tmp/local/* / data/db/
First back up the data in the original local folder to the / safe/data directory, and then move our pre-allocated space file / tmp/local/* to the data directory / data/db/, thus completing the manual pre-allocation of oplog space.
When you restart the master node, you can set the size of the oplog to 20g. Use the following command:
Mongod-master-oplogSize=20000
3) blocking replication use
When the replication of the slave node can not keep up with the write operation of the master node, in addition to changing the size of the oplog, there is another way to solve it, that is to block the write of the master node until the slave node slowly comes up and then release the blocking. Use the command as follows:
> db.runCommand ({getLastError:1,w:2})
The value of w indicates that at least 2 servers, including the primary node, have recorded the write operation before returning the write result. The value of w can be modified, the larger the value, the more obvious the blocking, and the slower the write operation.
This is how to manage the replica set in the MongoDB shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.