其它三个分片的配置类似
分别在每台机器上启动mongodb ./mongod -f /app/mongo/shard1/master/conf/mongod.conf登陆10.202.12.178,连接mongodb#设置第一个分片副本集./mongo 10.202.12.178#使用admin数据库use admin#定义副本集配置config = { _id:"shard1", members:[ {_id:0,host:"10.202.12.178:27017"}, {_id:1,host:"10.202.12.179:27017"}, {_id:2,host:"10.202.12.186:27017",arbiterOnly:true} ] }#初始化副本集配置rs.initiate(config);其它三个分片类似
配置路由服务器 目前搭建了mongodb配置服务器、路由服务器,各个分片服务器,不过应用程序连接到 mongos 路由服务器并不能使用分片机制,还需要在程序里设置分片配置,让分片生效 #连接到mongos./mongo 10.202.12.186:27018#使用admin数据库user admin#串联路由服务器与分配副本集1db.runCommand( { addshard : "shard1/10.202.12.178:27017,10.202.12.179:27017,10.202.12.186:27017"});#串联路由服务器与分配副本集2db.runCommand( { addshard : "shard2/10.202.12.180:27017,10.202.12.181:27017,10.202.12.189:27017"});#串联路由服务器与分配副本集3db.runCommand( { addshard : "shard3/10.202.12.182:27017,10.202.12.183:27017,10.202.12.192:27017"});#串联路由服务器与分配副本集4db.runCommand( { addshard : "shard4/10.202.12.184:27017,10.202.12.185:27017,10.202.12.194:27017"});#查看分片服务器的配置db.runCommand( { listshards : 1 } );配置分片规则 目前配置服务、路由服务、分片服务、副本集服务都已经串联起来了,但我们的目的是希望插入数据,数据能够自动分片,连接在mongos上,准备让指定的数据库、指定的集合分片生效指定countly数据库分片生效db.runCommand( { enablesharding :"countly"});指定数据库里需要分片的集合和片键db.runCommand( { shardcollection : "countly.user",key : {id: 1} } )新闻热点
疑难解答