以上配置复制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
(编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|