I. MongoDB Shard WIN7 simulation of multi-node additions and removal of shards

Source: Internet
Author: User


This paper mainly introduces the simulation of MONGO shards on a win7 computer . If you have more than one server, you can deploy each MONGO on a single computer. We will configure 3 MONGO shards,3 configuration servers,1 A routing server. As shown in the configuration, describes how to increase shards, remove shards.




A Download MongoDB

:http://www.mongodb.org/



Two Download the Windows Zip version, unzip it into a directory, and copy 7 copies, named as:


Three The contents of the config.bat file are established in the bin directory as described in the table below.

Note The Data folder is built under the MONGODB_XXXX directory


Note: In the routing configuration:mongos--port 2222--configdb 127.0.0.1:2001,127.0.0.1:2002,127.0.0.1:2003

means connecting the router to the configuration server so that they can recognize each other.


Four Start: Start MONGO in the following order, respectively

1. Click Configure Config.bat for Server 1 to start the configuration

2. Click Configure Config.bat for Server 2 to start the configuration

3. Click Configure Config.bat for Server 3 to start the configuration

4. Click Config.bat on Router 1 to start the routing service

5. Click Config.bat of Shard 1 to start the Shard

6. Click Config.bat of Shard 2 to start the Shard

7. Click Config.bat of Shard 3 to start the Shard

Note: After you start the Shard, there is no connection between the shards and the route, and they are independent, adding shards through the next step.

Five Enter the cmd command Terminal, execute the following statement,client connection mongos, note with admin Connection



Six Add shards by executing the addshard command, add 2004,2005,2006 Port Shard

Seven Adding data sets for shards, testing shards

1. We set the collection database named: Blog to enable sharding with the following statement:

2. To make a shard, you must specify a collection and a slice key, assuming that we fragment the blog system time with the author, execute the following statement:

Note that theblog is the database name andposts is similar to the table name in the relational type. If you want to shard a collection that already contains data, you must have an index on the data slice key.

All documents must also have a slice key value (and cannot be null).

Eight Shard Optimization Note

1. Set shard maximum data size based on Shard disk capacity execute the following statement , Adding a shard and using only 20GB

Db.runcommand (' Addshard ': ' 127.0.0.1:2007 ', ' maxSize ': 20000);

2. When adding a new Shard, it should be added when the MONGO is not highly loaded, and the MONGO will migrate the data to the hard disk when the data is migrated, so the query will be very full.

Nine Remove Shards

1. Sometimes it is also necessary to remove the Shard and execute the following command:

At this point, draining started successfunlly indicates that a shard removal is taking place, and the data on the 2006 is migrated to other shards, a process that is time consuming. Use the following command to detect if the removal has been completed.

2. Detect whether to complete the removal of the Shard, execute the down statement again, return completed, indicating that the removal is complete, after the removal of the 2006 can do any action, the shutdown does not matter.

3. If a replica set is used and a replica set is modified, the replica set master server should be connected to modify the corresponding configuration.

I. MongoDB Shard WIN7 simulation of multi-node additions and removal of shards

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.