I. mongodb sharding: add and remove shards on multiple simulated nodes in win7 environment. mongodbwin7

Source: Internet
Author: User
Tags mongodb sharding

I. mongodb sharding: add and remove shards on multiple simulated nodes in win7 environment. mongodbwin7

This article describes how to simulate mongo sharding on a win7 computer. If you have multiple servers, you can deploy each mongo on a single computer. We will configure three mongo shards, three configuration servers, and one Routing Server. Configure as shown in. This section describes how to add and remove parts.




1. Download mongodb

: Http://www.mongodb.org/



2. Download windows zip, decompress it to a directory, and copy 7 copies. The name is as follows:


3. Create the config. bat file in the bin directory as described in the following table.

Note that the data folder is created under the mongodb_xxxx directory.


Note: In route configuration, mongos -- port 2222 -- configdb 127.0.0.1: 2001,127.0 .0.1: 2002,127.0 .0.1: 2003

Connect the router with the configuration server so that they can know each other.


4. Start mongo in the following order:

1. Click config. bat of Server 1 to start the configuration.

2. Click config. bat of Server 2 to start the configuration.

3. Click config. bat of Server 3 to start the configuration.

4. Click config. bat of vro1 1 to start the routing service.

5. Click config. bat of part 1 to start the part.

6. Click config. bat of Part 2 to start the part.

7. Click config. bat of Part 3 to start the part.

 

Note: After the slice is started, there is no connection between the slice and the route. They are independent. Add the slice in the following step.

 

5. log on to the cmd command terminal and run the following statements to connect the client to mongos. Use admin to connect to mongos.



6. Run the addShard command to add shards. The command is as follows: add shards for ports 2006 and.

 

7. Add a data set for the parts and test the parts.

1. Set the name of the set database to blog. Use the following statement to enable the sharding:

 

 

2. You must specify a set and a partition key for sharding. If we perform sharding on the blog system time and author, run the following statement:

 

Note that a blog is a database name, and posts is similar to a relational table name. If you want to partition a set that already contains data, the Data Partition key must have an index.

All documents must also have partition key values (and cannot be null ).

 

8. Considerations for optimizing parts

1. Set the maximum data volume of a shard Based on the shard disk capacity. Execute the following statement to add a shard and use only 20 GB.

Db. runCommand ('addshard ': '192. 0.0.1: 100', 'maxsize': 127 );

 

2. when adding a new Shard, you should add it when mongo is not under high load. Otherwise, mongo will migrate the data being used by the application to the hard disk during data migration, in this way, the query will be very full.

 

9. Remove parts

1. Sometimes you also need to remove the parts and execute the following command:

 

 

In this case, draining started successfunlly indicates that the Shard is being removed, and the data on 2006 will be migrated to other shards. This process is very time-consuming. Run the following command to check whether the removal has been completed.

 

2. Check whether the part is removed. Execute the statement again and return completed, indicating that the part is removed. After the part is removed, you can perform any operation on 2006. shutdown does not matter.

 

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

Reprinted please indicate the original address: http://blog.csdn.net/tianyijavaoracle/article/details/41643649

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.