以上设置复制4份,修改一下数据库路径/日记路径/处事器IP和端口/PID路径,启动4个Shard Server:
- sudo bin/mongod -f shard1.conf
- sudo bin/mongod -f shard2.conf
- sudo bin/mongod -f shard3.conf
- sudo bin/mongod -f shard4.conf
设置处事器
4.0版本的MongoDB中设置处事器(Config Server)必要配置副本集,同时配置configsvr=true,设置参考如下:
- # 指定命据库路径
- dbpath=/usr/local/mongodb/share/5/data/db
- # 行使追加的方法写日记
- logpath=/usr/local/mongodb/share/5/log/mongodb.log
- # 行使追加的方法写日记
- logappend = true
- # 绑定处事IP
- bind_ip=127.0.0.1
- # 处事器端口
- port = 27100
- # 以保卫历程的方法运行MongoDB,建设处事器历程
- fork = true
- # PID File 的完备路径
- pidfilepath=/usr/local/mongodb/var/mongod27100.pid
- # 不启用验证
- noauth=true
- # 最大同时毗连数,默认2000
- maxConns=2000
- # 同步复制的日记巨细配置,单元MB
- oplogSize=10
- # 设置为config server
- configsvr=true
- # 副本集名称
- replSet=rs0
启动Config Server,并初始化副本集:
- sudo bin/mongod -f shard-config.conf
- mongo 127.0.0.1:27100
- > rs.initiaze()
新版本MongoDB提议配置多个Config Server,回收副本集情势配置集群,为了搭建利便,这里我们只回收单个Config Server。
路由处事器
Router Server不存放数据,设置参考如下:
- # 行使追加的方法写日记
- logpath=/usr/local/mongodb/share/6/log/mongodb.log
- # 行使追加的方法写日记
- logappend = true
- # 绑定处事IP
- bind_ip=127.0.0.1
- # 处事器端口
- port = 4000
- # 以保卫历程的方法运行MongoDB,建设处事器历程
- fork = true
- # PID File 的完备路径
- pidfilepath=/usr/local/mongodb/var/mongod4000.pid
- # 配置监听的config处事器
- configdb=rs0/127.0.0.1:27100
启动Router Server,路由处事器是由mongos呼吁启动,与分片处事器及设置处事器差异。
- sudo bin/mongos -f shard-router.conf
启动后,必要通过sh.addShard()呼吁添加分片处事器:
- sh.addShard('127.0.0.1:27020')
- sh.addShard('127.0.0.1:27021')
- sh.addShard('127.0.0.1:27022')
- sh.addShard('127.0.0.1:27023')
设置完成后,可以通过sh.status()呼吁,查察分片环境:
- mongos> sh.status()
- --- Sharding Status ---
- sharding version: {
- "_id" : 1,
- "minCompatibleVersion" : 5,
- "currentVersion" : 6,
- "clusterId" : ObjectId("5d8ddd1d94796dc650e29f67")
- }
- shards:
- { "_id" : "shard0000", "host" : "127.0.0.1:27020", "state" : 1 }
- { "_id" : "shard0001", "host" : "127.0.0.1:27021", "state" : 1 }
- { "_id" : "shard0002", "host" : "127.0.0.1:27022", "state" : 1 }
- { "_id" : "shard0003", "host" : "127.0.0.1:27023", "state" : 1 }
- active mongoses:
- "4.2.0" : 1
- autosplit:
- Currently enabled: yes
- balancer:
- Currently enabled: yes
- Currently running: no
- Failed balancer rounds in last 5 attempts: 0
- Migration Results for the last 24 hours:
- No recent migrations
- databases:
- { "_id" : "config", "primary" : "config", "partitioned" : true }
- config.system.sessions
- shard key: { "_id" : 1 }
- unique: false
- balancing: true
- chunks:
- shard0000 1
- { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$max
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|