MongoDB sharding and removal in the Win7 environment

Source: Internet
Author: User
Tags mongodb sharding

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, and 1 routing servers. As shown in the configuration, describes how to increase shards, remove shards.

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

two. 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.

Three . 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, the shards and There is no connection established between the routes , they are independent, and the shards are increased by the following step .

Iv. . Enter the cmd command terminal, execute the following statement, client connection MONGOs, note with admin connection

Five . Add shards by executing the addshard command, which increases the shard of the 2004,2005,2006 port as follows

Six . Adding data sets for shards, testing shards

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

Db.runcommand ({enablesharding: "blog"})

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: I use "_id" as the tablet key , Db.runcommand ({shardcollection: "blog.posts", key:{"_id": 1})

, note that the blog is the name of the database and posts 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).

Vii. use of MongoDB after fragmentation

Through the above six steps, MongoDB Shard has been completed, can be used directly.

The above we have created so many MongoDB port, then we really want to link to the MongoDB ports? In fact, we can only use the MONGOs port (that is, 2222) to control other processes. Since the other configuration servers were strung to the MONGOs in the configuration information of the MONGOs, we would like to use the MONGOs as a MongoDB service.

viii. sharding 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 in progress and will migrate data on 2006 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, the removal can be done to 2006 any action, shutdown also 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.

Reference: http://www.shangxueba.com/jingyan/2897358.html

MongoDB sharding and removal in the Win7 environment

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.