MongoDB Shard (sharding)

Source: Internet
Author: User
Tags database sharding

1. Concept

Sharding (sharding) refers to the process of splitting data and dispersing it across different machines. This concept is sometimes represented by partitioning (partitioning). Spread the data across different machines without the need for powerful mainframe computers to store more data and handle more load.

2. sharding

MONGOs is a routing server that will distribute the data to the Mongod cluster that it manages, according to the "Slice key" set by the administrator, and the correspondence between the data and slices and the corresponding configuration information on the "config server". Mongod: An ordinary database instance, if not sharding, we will directly connect to the Mongod.

3. If you implement Sharding

① create three directories to hold two Mongod service data Files and Config service data files

② Open config server. MONGOs to put the configuration between the Mongod in the config server, so first open it, here use 2222 port.

Command: Mongod--dbpath E:\sharding\config_node--port 2222

③ Open the MONGOs server. It is important to note that we are opening MONGOs, Port 3333, and specifying the next config server.

The command is: MONGOs--port 3333--configdb=127.0.0.1:2222

④ start the Mongod server. For the Shard, that is, to add a piece, here to open two Mongod services, the port is: 4444,5555. The command is:

Mongod--dbpath E:\sharding\mongod_node1--port 4444
Mongod--dbpath E:\sharding\mongod_node2--port 5555

⑤ service configuration. The client deals directly with MONGOs, which means that we want to connect the MONGOs server, and then give 4444,5555 Mongod to MONGOs, adding shards that is Addshard ().

⑥ Open the database sharding function, the command is very simple enablesharding (), this opens the test database.

⑦ Specifies the slice key of the Shard in the specified collection, which is specified as the Person.name key.

⑧ inserts a 10w record through MONGOs, and then uses the Printshardingstatus command to view MongoDB's data fragmentation situation.

Here are the main points to see three information:
①shards: You can see that it has been divided into two pieces, shard0000 and shard0001.
②databases: Here is a partitioned field that indicates whether the partition is partitioned, and here you can see that the test is partitioned.
③chunks: The collection is cut into four segments:
Infinitely small--jack0,
jack0--jack234813,
jack234813--jack9999,
jack9999--infinitely large.

The partitioning situation is: 3:1, which can be seen from the back of the on shardxxxx.

MongoDB Shard (sharding)

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.