为什么要进行分片
Mongodb2.6.0简单分片实验:
./mongod --shardsvr --replSet shard1 --port 27021 --dbpath /data/db/shardserver1 --logpath /data/logs/shardserver1.log --logappend --pidfilepath /data/pids/shardserver1.pid --fork
./mongod --shardsvr --replSet shard2 --port 27022 --dbpath /data/db/shardserver2 --logpath /data/logs/shardserver2.log --logappend --pidfilepath /data/pids/shardserver2.pid --fork
./mongod --shardsvr --replSet shard3 --port 27023 --dbpath /data/db/shardserver3 --logpath /data/logs/shardserver3.log --logappend --pidfilepath /data/pids/shardserver3.pid --fork
shardserver1:
mongo 10.88.88.11:27021
config = {_id:"shard1",members:[{_id:0,host:"10.88.88.11:27021"}]}
rs.initiate(config)
shardserver2:
mongo 10.88.88.11:27022
config = {_id:"shard2",members:[{_id:0,host:"10.88.88.11:27022"}]}
rs.initiate(config)
shardserver3:
mongo 10.88.88.11:27023
config = {_id:"shard3",members:[{_id:0,host:"10.88.88.11:27023"}]}
rs.initiate(config)
./mongod --configsvr --port 28001 --dbpath /data/db/configserver1 --logpath /data/logs/configserver1.log --logappend --pidfilepath /data/pids/configserver1.pid --fork
./mongos --port 40000 --logpath /data/logs/routeprocess.log --logappend --pidfilepath /data/pids/routeprocess.pid --configdb 10.88.88.11:28001 --fork &
mongo --port 40000 admin
db.runCommand({addshard:"shard1/10.88.88.11:27021"})
db.runCommand({addshard:"shard2/10.88.88.11:27022"})
db.runCommand({addshard:"shard3/10.88.88.11:27023"})
use shardtest
sh.enableSharding('shardtest')
sh.shardCollection('shardtest.users',{uid:1})
for(i=1;i<=100000;i++) db.users.insert({uid:i,name:'lee'+i,age:22})
sh.status(true)