Mongodb Study Notes 09, mongodb Study Notes

Source: Internet
Author: User

Mongodb Study Notes 09, mongodb Study Notes
Overview

Shard sharding divides different data into different servers.

Model

Where:
All user operations on mongodb are requested from mongs.
Configsvr is used to save a piece of data on which shard

How to use parts

Start two nodes 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-Configsvr

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

Start mongosNote:-configdb specifies configsvr

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

Connect to mongos

mongo --port 27020

Add the preceding two nodes

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

View status

sh.status()

Define sharding rulesFor example, declare that the test database can be sharded first, and then define the partitions Based on the my_id of my table.

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

Sharding Principle
N documents form a "chunk" and put it on a shard first. When the chunk number on this shard is different from the chunk number on other shard, move the chunk to another shard.

Modify the chunk size: For example, to 4 m
The default chunk size is 64 MB.

use configdb.setting.save({_id:'chunksize',value:4m})
Manual pre-partitioning

In the previous sharding method, shards are based on the number of chunks, which may affect IO.
You can manually pre-create parts, for example, define my_id 0 ~ 1000 put in shard1, 1001 ~ 2000 put in shard2, 2001 ~ Put in shard3 in 3000

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 Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.