第一步.启动相应的Mongod进程
mongod --fork --slave --port 27017 --replSet mySet --rest --dbpath /data/dbmongo/shard11 --logpath /data/dbmongo/shard11.log mongod --fork --slave --port 27018 --replSet mySet --rest --dbpath /data/dbmongo/shard12 --logpath /data/dbmongo/shard12.log mongod --fork --slave --port 27019 --replSet mySet --rest --dbpath /data/dbmongo/shard13 --logpath /data/dbmongo/shard13.log mongod --fork --slave --port 27020 --replSet mySet --rest --dbpath /data/dbmongo/shard14 --logpath /data/dbmongo/shard14.log
>config = {_id:'mySet',members:[{_id:0, host:'192.168.1.111:27017'},{_id:1, host:'192.168.1.112:27018'},{_id:1, host:'192.168.1.113:27019'},{_id:2, host:'192.168.1.114:27020'}}]} >rs.initiate(config); >rs.status();
192.168.1.100 mongod --fork --configsvr --port 20000 --rest --dbpath /data/dbmongo/config --logpath /data/dbmongo/config/config.log
mongos -fork --port 30000 --chunkSize 1 --configdb "192.168.1.100:20000" --logpath /data/dbmongo/mongos.log
192.168.1.100 >mongo 192.168.1.100:30000 >use admin >db.runCommand({addshard:'mySet/192.168.1.115:27021,192.168.1.116:27022'}); >db.runCommand({enablesharding:'test'}); >db.runCommand({listshards:1}); >printShardingStatus(); >db.runCommand({shardcollection:'test.test',key:{_id:1},unique:true});
>for(var i=1;i<=2011;i++)b.test.save({id:i,value1:"1234567890",value2:"1234567890",value3:"1234567890",value4:"1234567890"});