MongoDB Cluster and Shard 1

Source: Internet
Author: User

Shard Cluster

The data shard in MongoDB is called Chunk, which is a continuous data record in a collection, but it has a size limit that can not exceed 200M if the new shard is generated. Here is a simple instance of a shard cluster the composition of a shard cluster:
    • Shard Server:mongod instances for storing actual blocks of data
    • A Config Server:mongod instance that stores the entire cluster Metadata, including chunk information.
    • The route Server:mongos instance, as the front-end route for the entire cluster, is connected to the entire cluster. So that the whole cluster looks like a single process database.
    • Note: Route as routing forwards the request to the actual target service process, merging multiple results and returning the client. The route does not store any data and status, all information is retrieved from the config server when it is started, and when information is updated on the config server, it is also synchronized to the route server.
build a simple clusterCluster directory: A total of four MongoDB, the directory is/home/scotte.ye/mongo1,mongo2,mongo3,mongo4, which mongo1,mongo2 as Shard Servermongo3 as Config Servermongo4 as Route server 1. Start Shard ServerStart Shard server 1 $ cd/home/scotte.ye/mongo1$./mongo-shardsvr-port 10000-dbpath=/home/data/10000/-fork-logpath=/h ome/log/10000/null$ all output going to:/home/log/10000/null$ fork process:10657//Start Shard server 2 $ cd/home/scotte.ye /mongo2$./mongo-shardsvr-port 10011-dbpath=/home/data/10011/-fork-logpath=/home/log/10011/null$ all output going to :/home/log/10011/null$ fork process:10661//start config server $ cd/home/scotte.ye/mongo3$./mongo-configsvr-port 20000 -dbpath=/home/data/20000/-fork-logpath=/home/log/20000/null$ all output going to:/home/log/20000/null$ fork Process: 10857//Start route server $ cd/home/scotte.ye/mongo4$./mongos-configdb 192.168.35.106:20000-fork-logpath=/home/log/ 20000/null$ all output going to:/home/log/20000/null$ fork process:10900//Note When you start the route server, You can also configure the size of the tiles by using the-chunksize parameter 2. Configuration relatedConfiguration related Command Description:
    • Addshard: Add Shard Server to the cluster. Similar orders, Listshards and Removeshard.
    • Enablesharding: Used to set up those databases that can be distributed stored
    • Shardcollection: The name of the collection that is used to set the specific Shard, and the share key must be specified, the system automatically creates the index
    • Note: The Shardcollection collection must have only one unique index and must be shard key
Start configuration: $ cd/home/scotte.ye/mongo3/bin$./mongo$ >use admin$ #只有在admin数据库才可以操作 $ switched to DB admin$ >db.runcommand ( {addshard: ' 192.168.35.106:10000 '}) $ {"shardadded": "shard0000", "OK": 1}$ >db.runcommand ({addshard: ' 192.168.35.106:10011 '}) $ {"shardadded": " Shard0001 "," OK ": 1}$ #添加相应到shard server to Shard cluster$ >db.runcommand ({enablesharding: ' Test '}) $# make the corresponding database table test can be distributed storage, test can be replaced with the corresponding other database name $ >db.runcommand ({sahrdcollection: ' Test.user ', Key:{_id:1}}) $ {"OK": 1}$# Indicates the corresponding collection and shard key$ {"collectionsharded": "Test.user", "OK": 1} 3, common status query commands
    • printshardingstatus (): View sharding information
    • db.<collection_name>.stats (): View specific shard storage information
    • Isdbgrid: Used to confirm whether the current is sharding cluster
    • ismaster: Determine if it is master
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.