mongod --port 32770 --shardsvr --dbpath "D:\db\mongodata\shard\mongodb1" --logpath "D:\db\mongodata\shard\mongodb1.log"  --serviceName "mongodb1" --serviceDisplayName "mongodb1" --install
mongod --port 32771 --shardsvr --dbpath "D:\db\mongodata\shard\mongodb2" --logpath "D:\db\mongodata\shard\mongodb2.log"  --serviceName "mongodb2" --serviceDisplayName "mongodb2" --install

mongod --port 26010 --configsvr --replSet cs --dbpath "D:\db\mongodata\shard\mongodbConfig" --logpath "D:\db\mongodata\shard\mongodbConfig.log"  --serviceName "mongodbConfig" --serviceDisplayName "mongodbConfig" --install
mongod --port 26011 --configsvr --replSet cs --dbpath "D:\db\mongodata\shard\mongodbConfig1" --logpath "D:\db\mongodata\shard\mongodbConfig1.log"  --serviceName "mongodbConfig1" --serviceDisplayName "mongodbConfig1" --install

mongo 127.0.0.1:26010
cfg = {  
    _id:'cs',  
    configsvr:true,  
    members:[  
        {_id:0,host:'127.0.0.1:26010'}  
     ]  
};  
  
rs.initiate(cfg); 
rs.add({_id:1,host:'127.0.0.1:26011'})  

mongos --port 8001 --configdb cs/127.0.0.1:26010,127.0.0.1:26011 --logpath "D:\db\mongodata\shard\mongos.log"  --serviceName "mongos-a" --serviceDisplayName "mongos-a" --install
mongo 127.0.0.1:8001  
sh.addShard('127.0.0.1:32770')  
sh.addShard('127.0.0.1:32771')  
sh.status()  
sh.enableSharding('aedata')  
sh.shardCollection('aedata.ac01_test',{'id':1,'idcard':1})  
use aedata  
db.createUser({user:'aedata', pwd:'111111',roles:[{role:'readWrite',db:'aedata'}]})  
use aedata  
for(var i=10000; i<=20000; i++){ db.ac01_test.save({id:i,idcard:"card"+i}); }  
db.ac01_test.count()  
db.ac01_test.stats()  

 

posted on 2018-05-31 19:07  chester·chen  阅读(150)  评论(0编辑  收藏  举报