mogno集群

mongod --dbpath d:\mongodb\db\ --port 27021


mongod --dbpath c:\mongodb\db\ --port 27020

mongod --configsvr --dbpath e:\mongodb\db\ --port 27022

启动mongos的时候应将其连接到1个配置服务器上:
mongos --port 30000 --configdb 127.0.0.1:20000 --logpath "F:\mongo\logs\mongos\MongoDB.txt"
启动mongos的时候应将其连接到3个配置服务器上:
mongos --port 30000 --configdb 127.0.0.1:20000,127.0.0.1:20001,127.0.0.1:20002 --logpath "F:\mongo\logs\mongos\MongoDB.txt"


添加sharding,maxsize单位是M,此处设置比较小的数值只为演示sharding效果
db.runCommand({"addshard":"127.0.0.1:27018",name:"shard1",maxsize:2048,"allowLocal":true})
db.runCommand({"addshard":"127.0.0.1:27019",name:"shard2",maxsize:2048,"allowLocal":true})
注:如果要移除sharding,可用下面写法
db.runCommand( { removeshard : "localhost:10000" } );
查看shard节点列表
db.runCommand({listshards:1});

接下来创建相应数据库并设置其"可以sharding",新建自动切片的库user001:
config = connect("127.0.0.1:27020")
config = config.getSisterDB("config")
qnlbs=db.getSisterDB("qnlbs");
use admin
db.runCommand({enablesharding:"qnlbs"})
注:一旦enable了个数据库,mongos将会把数据库里的不同数据集放在不同的分片上。除非数据集被分片(下面会设置),否则一个数据集的所有数据将放在一个分片上。
db.printShardingStatus();


db.runCommand( { enablesharding : "qnmsg" } );

db.runCommand({ shardcollection: "qnlbs.user", key: { userID:1 }})
db.runCommand({ shardcollection: "qnmsg.user", key: { _id:1 }})


db.runCommand({"shardcollection":"test.refactor","key":{"name":1}})


db.pal.ensureIndex({ "pk" : 1},{ "pal" : "pk_1", "unique" : true });

db.user.ensureIndex({"userID":1});
db.runCommand({ shardcollection: "qnmsg.user", key: { _id:1 }})

db.runCommand( { shardcollection : "qnmsg.pal" } )
printShardingStatus()
db.pal.ensureIndex({"pal":1});


删除片操作
db.runCommand({"removeshard" : "10.0.0.11:27011"});
微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码 微信小程序毕业设计期末大作业项目源码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值