MongoDB分片集群搭建
一、设计集群的架构。
节点 | 主机 | 端口 | 副本集 |
---|---|---|---|
配置集节点 ConfigServer | localhost | 27019 | xxconfig |
路由服务器 Router | localhost | 27017 | n/a |
分片0节点0 | localhost | 27010 | xx0 |
分片0节点1 | localhost | 27011 | xx0 |
分片0节点2 | localhost | 27012 | xx0 |
分片1节点0 | localhost | 27013 | xx1 |
分片1节点1 | localhost | 27014 | xx1 |
分片1节点2 | localhost | 27015 | xx1 |
根据以上的架构,我们设计两个shard(分片0,分片1),一个config,一个路由节点router。采用PSA的模式,就是一主一从一仲裁的模式。配置集节点 ConfigServer采用单节点配置。下面就开动吧!
二、示意图。
针对以上的框架结构,我简略的画了一下示意图。
大概就是这个样子了,图画的有点丑,哈哈哈。
三、搭建副本集。
一、搭建thc0、thc1。
我是在Windows上面练习搭建的,所以我们首先进入到Windows的环境当中。也就是进入到MongoDB的bin目录下面。
我练习的是把所有的东西弄在一个文件夹shard当中,首先按照上面需求创建好文件目录。
thc0下面创建以下文件夹
thc1下面创建以下文件夹
也可以采用命令创建这些目录:
`mkdir \shard\thc0\thc00\data`
`mkdir \shard\thc0\thc00\log`
`mkdir \shard\thc0\thc01\data`
`mkdir \shard\thc0\thc01\log`
`mkdir \shard\thc0\thc02\data`
`mkdir \shard\thc0\thc02\log`
`mkdir \shard\thc1\thc10\data`
`mkdir \shard\thc1\thc10\log`
`mkdir \shard\thc1\thc11\data`
`mkdir \shard\thc1\thc11\log