MongoDB分布式

时间:2021-01-11 12:39:57
结构:
ShardServer1:27020
ShardServer2:27021
ShardServer3:27022
ShardServer4:27023
ConfigServer:27100
RouteProcess:40000
--设置shard服务器
mongod --port 27020--dbpath "D:/MongoDB/Data/shard/s0" --logpath "D:/MongoDB/Data/shard/log/s0.log" --logappend --fork
mongod --port 27021--dbpath "D:/MongoDB/Data/shard/s1" --logpath "D:/MongoDB/Data/shard/log/s1.log" --logappend --fork
mongod --port 27022--dbpath "D:/MongoDB/Data/shard/s2" --logpath "D:/MongoDB/Data/shard/log/s2.log" --logappend --fork
mongod --port 27023--dbpath "D:/MongoDB/Data/shard/s3" --logpath "D:/MongoDB/Data/shard/log/s3.log" --logappend --fork
--config服务器
mongod --port 27100--dbpath "D:/MongoDB/Data/shard/config" --logpath "D:/MongoDB/Data/shard/log/config.log" --logappend --fork
---Route
mongos --port 40000--configdb localhost:27100--fork --logpath "D:/MongoDB/Data/shard/log/route.log" --chunkSize 500 
--登录
mongo admin --port 40000
---添加分片
db.runCommand({ addshard:"localhost:27020"})
db.runCommand({ addshard:"localhost:27021"})
db.runCommand({ addshard:"localhost:27022"})
db.runCommand({ addshard:"localhost:27023"})
---#设置分片存储的数据库
db.runCommand({ enablesharding:"test"})
db.runCommand({ shardcollection:"test.log", key:{ id:1,time:1}})