MongoDB Learning Note--Shard Shard

Source: Internet
Author: User

Overview

Shard Sharding is the separation of different data on different servers.

Model

among them:
The user's operation to MongoDB is requested by the mongs.
CONFIGSVR is used for saving, which data is stored on which shard

How to use Shards

Start 2 nodes first as Shard

mongd --dbpath ~/db/mongo1/databse --logpath ~/db/mongo1/log/mongo.log --port 27017 --fork --smallfilesmongd --dbpath ~/db/mongo2/databse --logpath ~/db/mongo2/log/mongo.log --port 27018 --fork --smallfiles

start Configsvr, is more than the previous –configsvr

mongd --dbpath ~/db/mongo3/databse --logpath ~/db/mongo3/log/mongo.log --port 27019 --fork --smallfiles --configsvr

start MONGOs, note –configdb Specify CONFIGSVR

mongos --logpath ~/db/mongo4/log/mongs.log --port 27020  --configdb 127.0.0.1:27020 --fork

Even to MONGOs.

mongo --port 27020

Add the 2 nodes that are running ahead

sh.addShard("127.0.0.1:27017")sh.addShard("127.0.0.1:27018")

View status

sh.status()

define Shard Rules : For example, declare the test library to be fragmented, and then define the shards based on the my_id of my table

sh.enableSharding(‘test‘)sh.shardCollection(‘test.my‘,{‘my_id‘:1})

sharding principle
n Document, form a "chunk", first put on a shard, when this piece of Shard on the chunk number, than the Shard number on other chunk difference, move chunk to another shard.

Modify the size of the chunk : for example, modify to 4m
The default size of a chunk is 64m

use configdb.setting.save({_id:‘chunksize‘,value:4m})
Manual Pre-sharding

In the preceding Shard method, shards are based on the number of chunk, which can cause problems affecting IO.
You can manually pre-make shards, such as defining my_id 0~1000 in Shard1, 1001~2000 in Shard2, 2001~3000 on Shard3

sh.enableSharding(‘test‘)sh.shardCollection(‘test.my‘,{‘my_id‘:1})sh.splitAt(‘my‘,{my_id:1000})sh.splitAt(‘my‘,{my_id:2000})sh.splitAt(‘my‘,{my_id:3000})

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MongoDB Learning Note--Shard Shard

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.