Mongodb sharding trial (1)

Source: Internet
Author: User
Tags mongodb sharding

Knowledge Point: mongoDB Sharding is an automatic data Sharding. Data is automatically migrated in different data servers. The migration trigger conditions include the data volume and access traffic.

1. Create a sharding cluster in two parts: one is to start the corresponding mongoDB service, and the other is to decide how to split the data.

2. A sharding cluster that can provide services mainly consists of three parts:

(1) configuration server: A general mongoDB service process. It stores the correspondence between cluster data and slices. Configuration information is deployed.

(2) Routing Server: route request and forwarding result set. The Routing Server knows where the corresponding data is stored. It caches configuration server information but does not implement it, and synchronizes data from the configuration server.

(3) data server: a service process that truly stores data. It is a general mongoDB service process.

3. Create a sharded Cluster

1. Start the configuration service process. Because the Routing Server needs to synchronize data from the configuration server, it is necessary to start the routing service process early.

Mongod -- dbpath/exports/dbs/config -- port 20000

2. Start the Routing Server and specify the corresponding configuration server location. The routing service process does not need to specify the data file directory. It does not store data, but caches the data of the service process.

Mongos -- port 30000 -- configdb localhost: 20000

3. Start the data server. This is the mongodb process that actually stores data. (Use one at the beginning, and then add)

Mongod -- dbpath/exports/dbs/shard1 -- port 27017

4. Connect to the Routing Server to enable the slice. You must specify a set to a database.

Mongo localhost: 30000/admin

Db. runCommand ({addshard: "localhost: 27017", allowLocal: true });

5. Connect to the Routing Server and specify a set in a database to be split. And specify the shard key.

Db. runCommand ({enablesharding: "foo "});

Db. runCommand ({shardcollection: "foo. bar", key: {_ id: 1 }});

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.