In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about how to set up a sharding cluster in mongodb. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
1. Enable sharding first, and enable the sharding function of the database
Mongos > use admin
Mongos > db.runCommand ({"enablesharding": "test1"})
2. To slice a specific collection, select the slice key as "_ id"
Mongos > db.runCommand ({"shardcollection": "test1.test1", "key": {"_ id": 1}})
{"collectionsharded": "test1.test1", "ok": 1}
3. Observe the number of shard_01 shard_02 tunks in 2 fragments
# Delete shards #
1. Make sure the equalizer is turned on
Mongos > use admin
Mongos > sh.setBalancerState (true)
Or mongos > sh.startBalancer ()
2. Migrate all the sharded collections to other shards
Use admin
Db.adminCommand ({"removeShard": "shard_name"})
3. Check the status of block migration. The remaining field indicates the number of remaining blocks.
Use admin
Db.runCommand ({removeShard: "shard_name"})
= # Delete unsharded database # =
1. View the database that is not sharded
Use config
Db.databases.find ({$or: [{"partitioned": false}, {"primary": "shard_name"}]})
2. Modify the main shard of the database
Db.runCommand ({movePrimary: "db_name", to: "new_shard"})
= # refresh the configuration cache of mongos # =
Forces mongos to synchronize configuration information from config server and flush the cache
Use admin
Db.adminCommand ({flushRouterConfig: 1})
= oplog to do daily automatic log rotation
1. Add parameters to the configuration file
Logpath=/data/shard_01/mongodb.log
Logappend=true
2. Set scheduled tasks
0 * / bin/kill-SIGUSR1 `cat / data/shard_01/ mongodb.log`
Oplog size can be modified online in mongodb 3.6or later
Use local
Db.adminCommand ({replSetResizeOplog: 1, size: 100000})
After reading the above, do you have any further understanding of how to set up sharding clusters in mongodb? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.