当前位置:Gxlcms > 数据库问题 > monodb分片集群部署

monodb分片集群部署

时间:2021-07-01 10:21:17 帮助过:34人阅读

 

mongo -port 47017

 

rs.initiate({_id:"shard2RS",members:[{_id:1,host:"192.168.141.202:47017",priority:2},{_id:2,host:"192.168.141.201:47017"},{_id:3,host:"192.168.141.203:47017"}]})

 

同上完成端口57017配置

配置分片,将主片添加至集群

mongo -port 17017

 

>use admin

>db.runCommand({"addShard":"shard1RS/192.168.141.201:37017" ,"maxsize":1024})

>db.runCommand({"addShard":"shard2RS/192.168.141.202:47017" ,"maxsize":1024})

>db.runCommand({"addShard":"shard3RS/192.168.141.203:57017" ,"maxsize":1024})

使用,在使用的时候,需要对数据库开启分片功能,并对数据库下的表的字段指定分片算法

>use admin

--对库hdctest开启分片

>db.runCommand({"enablesharding":"hdctest"})

--对库hdctest下的表person按字段ID配置hash分库算法

>db.runCommand({"shardcollection":"hdctest.person","key":{_id:‘hashed‘}})

注意:登陆从库查看数据信息的时候,可能会报:

not master and slaveOk= false,code=13435

执行:

db.getMongo().setSlaveOk()

monodb分片集群部署

标签:127.0.0.1   option   ons   group   host   server1   node   设计   beat   

人气教程排行