MONGODB10---Shards

Source: Internet
Author: User

Shard: Data is very large, the data of different segments are removed, 1-1000000 placed on the node 1,1000000-2000000 node 2,200000-300000 placed on the node. Put different data on different servers called Shard shards.

request to MONGOs, people to mongos data write data.

1: On 3 separate servers, run separately27017,27018, 27019 instances, each replica set, forming 3 sets of REPLSet2: On 3 servers, configure Config server, run on port 270203: Configure MONGOs./Bin/MONGOs--Port 30000 \ --dbconfig 192.168.1.201:27020,192.168.1.202:27020,192.168.1.203:270204: Connect the router./Bin/Mongo--Port 300005: Add Repl Set as Slice>Sh.addshard ('192.168.1.201:27017');>Sh.addshard ('192.168.1.203:27017');>Sh.addshard ('192.168.1.203:27017');6: Add a library to be fragmented>sh.enablesharding (databaseName);7: Adding tables to be partitioned>Sh.shardcollection (' Dbname.collectionname ', {field:1}); field is a field of collection, and the system will use the value of filed to calculate which slice it should be on. This filed is called the "Tablet Key", ShardKey
MongoDB is not from the level of a single document, the absolute average scattered on each piece, but the N document, form a block "chunk", priority on a piece, the piece is divided into a block, when this piece of chunk, than another piece of chunk, the difference is relatively large, (  >=3), the chunk on the film will be moved to another film, in order to chunk units, maintenance of data between the pieces of the balance Q: Why 100,000 data inserted, only 2 chunk? A: Description chunk is larger (default is 64M) in the Config database, modify the value of chunksize.  Use configshow tablesDb.settings.find ();     // {ID: ' chunksize ', ' value ':+} Q: Since the priority to insert on a piece, when the chunk imbalance, then move chunk, naturally, with the increase in data, shard instances, there is chunk move back and forth phenomenon, What is the problem? A: The increase of IO between servers, then ask: can I define a rule, a certain n data form 1 blocks, the pre-allocation of M chunk,m chunk trailer assigned on different slices. Future data directly into their pre-allocated chunk, no longer moving back and forth? A: Yes, manual pre-shard!
Mkdir-P/Data/R17/Data/R18/Data/R20/Data/Mlog// -, 18 is the port of Shard, 20 is the port of Configsvr//start an instance of 2 MONGO slices/Usr/Local/Mongodb/Bin/Mongod--dbpath/data/r17/--logpath/data/mlog/r17.log--port 27017--fork--smallfile/Usr/Local/Mongodb/Bin/Mongod--dbpath/data/r18/--logpath/data/mlog/r18.log--port 27018--fork--smallfile//Prepare configsvc (not a server that stores data, but a server that stores configuration information)/Usr/Local/Mongodb/Bin/Mongod--dbpath/data/r20/--logpath/data/mlog/r20.log--port 27020--fork--configsvr//MONGOs Router/Usr/Local/Mongodb/Bin/MONGOs--logpath/data/mlog/r30.log--port 30000--configdb 192.168.202:27020--fork//which one configsvr serve him, Now MONGOs and Configsvr are connected, but not with Shard. PS aux|grep MONGO//you can see the 4 processes just now.//connect the MONGOs./Bin/Mongo--Port 30000//add Repl Set as slices, now 3 are all connected together,>Sh.addshard ('192.168.1.201:27017');>Sh.addshard ('192.168.1.203:27018'); Sh.status ()//can view shard information UseTestdb.stu.Insert({ss: "ss"}) Db.stu.Insert({ss: "ss"}) Db.stu.Insert({ss: "ss"}) Db.stu.Insert({ss: "ss"}) Db.stu.Insert({ss: "ss"})//connect to 27017./Bin/Mongo--Port 27017Db.find ()//have data//connect to 27018./Bin/Mongo--Port 27018Db.find ()//no data, because no shard rule is specified//add a library to be fragmented (who can shard)>Sh.enablesharding (' Shop');//Shop Library can be fragmented sh.status ()//you can see that the shop Gallery can be fragmented//adding tables to be partitioned>Sh.shardcollection ('Shop.goods', {goods_id:1}); Sh.status ()//you can see the status of the goods table in the Shop gallery//Add 2000 Data Use Shop for(varI=1; I<600000; I++) {db.goods.Insert({ss: "ss"+1})}db.goods.find ()//View Shard data./Bin/Mongo--Port 27017Db.find ()./Bin/Mongo--Port 27018Db.find ()

MONGODB10---Shards

Related Keywords:

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.