Created
June 6, 2013 18:11
-
-
Save rtoal/5723645 to your computer and use it in GitHub Desktop.
Transcript for the sharding example from a mongo workshop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p data/shard0/rs0 data/shard0/rs1 data/shard0/rs2 | |
mongod --replSet s0 --logpath "s0-r0.log" --dbpath data/shard0/rs0 --port 37017 --fork --shardsvr | |
mongod --replSet s0 --logpath "s0-r1.log" --dbpath data/shard0/rs1 --port 37018 --fork --shardsvr | |
mongod --replSet s0 --logpath "s0-r2.log" --dbpath data/shard0/rs2 --port 37019 --fork --shardsvr | |
mongo --port 37017 | |
config = {_id: "s0", members: [ | |
{_id: 0, host: "localhost:37017" }, | |
{_id: 1, host: "localhost:37018" }, | |
{_id: 2, host: "localhost:37019" }]}; | |
rs.initiate(config); | |
^D | |
mkdir -p data/shard1/rs0 data/shard1/rs1 data/shard1/rs2 | |
mongod --replSet s1 --logpath "s1-r0.log" --dbpath data/shard1/rs0 --port 47017 --fork --shardsvr | |
mongod --replSet s1 --logpath "s1-r1.log" --dbpath data/shard1/rs1 --port 47018 --fork --shardsvr | |
mongod --replSet s1 --logpath "s1-r2.log" --dbpath data/shard1/rs2 --port 47019 --fork --shardsvr | |
mongo --port 47017 | |
config = {_id: "s1", members: [ | |
{_id: 0, host: "localhost:47017" }, | |
{_id: 1, host: "localhost:47018" }, | |
{_id: 2, host: "localhost:47019" }]}; | |
rs.initiate(config); | |
^D | |
mkdir -p data/config/config-a data/config/config-b data/config/config-c | |
mongod --logpath "cfg-a.log" --dbpath data/config/config-a --port 57017 --fork --configsvr | |
mongod --logpath "cfg-b.log" --dbpath data/config/config-b --port 57018 --fork --configsvr | |
mongod --logpath "cfg-c.log" --dbpath data/config/config-c --port 57019 --fork --configsvr | |
mongos --logpath "mongos-1.log" --configdb localhost:57017,localhost:57018,localhost:57019 --fork | |
mongo | |
db.adminCommand( {addshard: "s0/localhost:37017"} ); | |
db.adminCommand( {addshard: "s1/localhost:47017"} ); | |
db.adminCommand( {enableSharding: "media"} ); | |
db.adminCommand( {shardCollection: "media.photos", key: {user: 1}} ); | |
show dbs | |
use media | |
db.photos.insert({user:'Alice', caption:'skiing', ts:1227389123744}); | |
db.photos.insert({user:'Bob', caption:'skiing', ts:1227388883749}); | |
db.photos.insert({user:'Carla', caption:'party', ts:1327388883749}); | |
for (i = 0; i < 1000; i++) { | |
db.photos.insert({user:Math.random().toString(36).substr(2,16), caption:'x'}); | |
} | |
sh.help() | |
sh.status() | |
db.photos.find({caption:'scuba'}).explain() | |
db.photos.find({user:'vladimir'}).explain() | |
db.photos.stats() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment