以下是在CentOS上实现MongoDB分片技术的基本步骤:
yum install -y mongodb-org命令安装。mongod --configsvr --replSet configReplSet --dbpath /data/configdb --port 27019。rs.initiate()命令。mongod --shardsvr --replSet shardReplSet --dbpath /data/db --port 27018。rs.initiate()。mongos --configdb configReplSet/cfg1:27019,cfg2:27019,cfg3:27019 --port 27017。sh.addShard("shardReplSet/shard1:27018,shard2:27018,shard3:27018")。sh.enableSharding("yourDatabase")。sh.shardCollection("yourDatabase.yourCollection", { "shardKey": 1 })。sh.status()查看集群状态,确认分片是否正常。注意事项:
参考资料: