MongDB Sharding
Anuchit Chalothorn
anuchit@redlinesoft.net
● 2 or more router servers
● 3 config server
● 2 or more shard server
Architecture
Sharded Cluster Architecture
Setup
All machine install MongoDB
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
tar zxvf mongodb-li...
Shard Server
Start service mongod on shard server
mongod --dbpath /data/db
Config Server
Start service mongod on config server
mongod --configsvr --dbpath /data/db
Router Server
Start service mongos on router server
mongos --configdb ◌ํYOUR-CONFIG-SERVER:27019
Add Shard to Cluster
Connect to router and add shard to cluster
sh.addShard("YOUR-SHARD-SERVER:27017")
Check your cluster status
Check your shard cluster status
sh.status()
Test your shard cluster
Select database ‘test’ to sharding
sh.enableSharding("test")
Test your shard cluster
Select database push some sample data
use test
for (var i = 1; i <= 10; i++) db.testSample.insert(...
Test your shard cluster
Index your collection
db.testSample.ensureIndex({ _id: "hashed" })
Test your shard cluster
Select shard key (Hash Based)
sh.shardCollection("test.testSample",{ "_id": "hashed" });
Test your shard cluster
Add more shard server and push more sample
data and see your shard status
MongoDB Shard Cluster
Upcoming SlideShare
Loading in...5
×

MongoDB Shard Cluster

433

Published on

MongoDB Shard Cluster

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
433
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

MongoDB Shard Cluster

  1. 1. MongDB Sharding Anuchit Chalothorn anuchit@redlinesoft.net
  2. 2. ● 2 or more router servers ● 3 config server ● 2 or more shard server Architecture
  3. 3. Sharded Cluster Architecture
  4. 4. Setup All machine install MongoDB wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz tar zxvf mongodb-linux-x86_64-2.6.1.tgz -C /opt/ export PATH=$PATH:/opt/mongodb-linux-x86_64-2.6.1/bin mkdir -p /data/db
  5. 5. Shard Server Start service mongod on shard server mongod --dbpath /data/db
  6. 6. Config Server Start service mongod on config server mongod --configsvr --dbpath /data/db
  7. 7. Router Server Start service mongos on router server mongos --configdb ◌ํYOUR-CONFIG-SERVER:27019
  8. 8. Add Shard to Cluster Connect to router and add shard to cluster sh.addShard("YOUR-SHARD-SERVER:27017")
  9. 9. Check your cluster status Check your shard cluster status sh.status()
  10. 10. Test your shard cluster Select database ‘test’ to sharding sh.enableSharding("test")
  11. 11. Test your shard cluster Select database push some sample data use test for (var i = 1; i <= 10; i++) db.testSample.insert({ x : i })
  12. 12. Test your shard cluster Index your collection db.testSample.ensureIndex({ _id: "hashed" })
  13. 13. Test your shard cluster Select shard key (Hash Based) sh.shardCollection("test.testSample",{ "_id": "hashed" });
  14. 14. Test your shard cluster Add more shard server and push more sample data and see your shard status
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×