In MongoDB there is another cluster, that is, sharding technology, similar to the SQL Server table partition, we know that when the amount of data reached the T level, our disk, memory
That's how we deal with this scenario.
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 "tablet key" set by the administrator.
and the corresponding configuration information is stored 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> we can also see in the previous figure that our client is dealing directly with MONGOs, which means we are going to connect the MONGOs server and then 4444,5555 Mongod
To MONGOs, add Shard is also 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 then insert the 10w record into MongoDB via MONGOs and then through the Printshardingstatus command
View the data sharding situation for MongoDB.
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:
Infinitely small--jack0,jack0--jack234813,jack234813--jack9999,jack9999--infinity.
The partitioning situation is: 3:1, which can be seen from the back of the on shardxxxx.
MongoDB Learning Summary-6 (Shard Technology)