Mongodb分片
mongod --port 3000 --shardsvr --replSet rs-a --dbpath “D:\software\MongoDB\data\data\rs-a-0” --logpath “D:\software\MongoDB\data\log\rs-a-0.log”
mongod --port 3001 --shardsvr --replSet rs-a --dbpath “D:\software\MongoDB\data\data\rs-a-1” --logpath “D:\software\MongoDB\data\log\rs-a-1.log”
mongod --port 3002 --shardsvr --replSet rs-a --dbpath “D:\software\MongoDB\data\data\rs-a-2” --logpath “D:\software\MongoDB\data\log\rs-a-2.log”
副本集配置
rs.status()
rs.initiate()
rs.isMaster()
rs.add(“localhost:3001”)
rs.add(“localhost:3002”)
rs.remove(“localhost:3001”)
rs.remove(“localhost:3002”)
rs.add(“172.16.1.9:3001”)
rs.add(“172.16.1.9:3002”)
rs.status()
配置服务器 配置Config——server
mongod --port 27019 --configsvr --replSet rs-conf --dbpath “D:\software\MongoDB\data\data\config0” --logpath “D:\software\MongoDB\data\log\config0.log”
mongod --port 27020 --configsvr --replSet rs-conf --dbpath “D:\software\MongoDB\data\data\config1” --logpath “D:\software\MongoDB\data\log\config1.log”
新开一个窗口 连接27019
rs.initiate()
回车 到RPIMARY
rs.add(“localhost:27020”)
配置路由服务器 注意加上端口号
mongos --port 27088 --configdb rs-conf/localhost:27019,localhost:27020 --logpath “D:\software\MongoDB\data\log\mongos.log”
添加创建的分片
连接时加上mongos的端口号 连接成功会显示 mongos>
将我们前面创建的分片添加进去,使用命令 mongo --port 27088
登录mongos,使用sh.addShard添加分片
sh.status() 查看分片的状态
sh.addShard(“rs-a/172.16.1.9:3000, 172.16.1.9:3001, 172.16.1.9:3002”)