mongod --port 10001 --logpath cluster/log/shard1.log --logappend --shardsvr -dbpath cluster/data/shard1 --directoryperdb --rest mongod --port 10002 --logpath cluster/log/shard2.log --logappend --shardsvr -dbpath cluster/data/shard2 --directoryperdb --rest mongod --port 20000 --logpath cluster/log/config.log --logappend --configsvr -dbpath cluster/data/config mongos --port 27017 --logpath cluster/log/mongos.log --logappend --configdb 127.0.0.1:20000 进入mongos,配置shard: mongo 127.0.0.1:27017/admin db.runCommand({ addshard : "127.0.0.1:10001"}) db.runCommand({ addshard : "127.0.0.1:10002"}) db.runCommand({ listshards : 1}) db.runCommand({ enablesharding : "test"}) db.runCommand({ shardcollection : "test.c1",key : {_id: 1} })
参考
mongodb sharding
时间: 2024-10-08 16:44:20