MongoDB is fragmented under windows

Source: Internet
Author: User
Tags database sharding

In MongoDB there is another cluster, is the Shard technology, similar to the SQL Server table partition, we know that when the amount of data reached the T level, our disk, memory is too much, for such a scenario we should deal with.

  One: Shard

MongoDB uses a solution that splits the collection and then splits the data into several slices.

Here I explain to this picture:

Face: On behalf of the client, the client must say, you do not shard database shard with me, I told you to do what you do, there is no good to discuss.

MONGOs: First we need to understand the concept of "chip key", that is, what is the basis for splitting the set? To split a collection by what key value .... Well, MONGOs is a routing server that will distribute the data to the Mongod cluster that it manages, based on the "Slice key" set by the administrator, and the corresponding relationship between the data and the slice and the corresponding configuration information on the "config server".

Mongod: An ordinary database instance, if not sharding, we will directly connect to the Mongod.

  Two: Actual combat

First of all we prepare 4 MongoDB program, I here is averaging on the c,d,e,f disk, of course you can also do multiple folders in the form.

1: Open config server

Previously said, MONGOs to put the configuration between mongod in the config server, it is a matter of course first open it, I set up 2222 port here.

2: Turn on the MONGOs server

Note here is that we open the MONGOs, not mongod, while specifying the next config server, here I opened the D drive MongoDB, Port 3333.

3: Start the Mongod server

For the Shard, that is, to add a piece, here to open the E,f disk MongoDB, Port: 4444,5555.

4: Service Configuration

Haha, is not very excited, and the last bit of configuration we can do it.

<1> as can be seen in the previous figure, our client deals directly with MONGOs, which means that we are going to connect the MONGOs server, and then give 4444,5555 Mongod to MONGOs, adding shards that is Addshard ().

It is important to note that in Addshard, we can also add replica sets to achieve higher stability.

<2> tablets have been clustered, but MONGOs do not know how to slice the data, which is what we said before the chip key, in MongoDB set up the tablet key to do two steps

①: Turn on the database sharding function, the command is very simple enablesharding (), here I open the test database.

②: Specifies the slice key of the Shard in the collection, which I specify as the Person.name field.

5: View Effects

Well, now that our Shard operation is all over, we are going to insert a 10w record into MongoDB via MONGOs and then view the data shards of MongoDB with the Printshardingstatus command.

Here are the main points to see three information:

①shards: We clearly see that we are not divided into two pieces, shard0000 and shard0001.

②databases: Here is a partitioned field that indicates whether the partition is partitioned, so it is clear that test is partitioned.

③chunks: This is interesting, we found that the collection was cut into four segments: Infinity--jack0,jack0--jack234813,jack234813--jack9999,jack9999--Infinity. The partitioning situation is: 3:1, which can be seen from the back of the on shardxxxx.

10

Reprinted from http://www.cnblogs.com/huangxincheng/

MongoDB is fragmented under windows

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.