1.简介
对于RocketMQ而言,我们需要部署的东西就是NameServer和BrokerServer。
①对于NameServer而言,它的作用就是路由,保存记录者BrokerServer的信息(Ip:port),当消费者、生产者操作某个Topic时,NameServer会告诉它们所需要的这个Topic所在BrokerServer的信息。
- nameserver记录brokerserver的信息
- nameserver服务器彼此之间不通信,因此,每个nameserver都保存着brokerserver的完整信息
- 因此,在部署时,你启动2台以上的nameserver就可以保证高可用。
②对于BrokerServer而言,由于Topic会进行分片存储到不同的BrokerServer中,因此需要对BrokerServer进行消息信息的备份。因此出现2主2从的官方部署架构,针对消息备份的同步和异步又分为2m-2s-async(2主2从异步复制),2m-2s-sync(2主2从同步复制)。
此外,RocketMq还提供了一种新的集群搭建方式,Dledger集群搭建,其架构图应该是我下面这幅图所想的。
2.新集群的搭建
- 搭建环境准备
①四台虚拟机、Linux系统
②ip如下
主机1: 192.168.56.200
主机2: 192.168.56.201
主机3: 192.168.56.202
主机4: 192.168.56.203
- 搭建结果图
- 搭建步骤
①主机1上拷贝rocketmq的tar包或zip包
②解压tar或zip包
③进入bin目录修改 runbroker.sh,修改内容如下:
④修改bin目录下的runserver.sh,修改结果如下:
⑤进入/conf/dledger 目录修改broker-n0.conf、broker-n1.conf、broker-n2.conf如下所示
broker-n0.conf
brokerClusterName = RaftCluster
brokerName=RaftNode00
listenPort=30911
namesrvAddr=192.168.56.200:9876
storePathRootDir=/tmp/rmqstore/node00
storePathCommitLog=/tmp/rmqstore/node00/commitlog
enableDLegerCommitLog=true
dLegerGroup=RaftNode00
dLegerPeers=n0-192.168.56.201:40911;n1-192.168.56.202:40912;n2-192.168.56.202:40913
## must be unique
dLegerSelfId=n0
sendMessageThreadPoolNums=16
broker-n1.conf
brokerClusterName = RaftCluster
brokerName=RaftNode00
listenPort=30921
namesrvAddr=192.168.56.200:9876
storePathRootDir=/tmp/rmqstore/node01
storePathCommitLog=/tmp/rmqstore/node01/commitlog
enableDLegerCommitLog=true
dLegerGroup=RaftNode00dLegerPeers=n0-192.168.56.201:40911;n1-192.168.56.202:40912;n2-192.168.56.203:40913
## must be unique
dLegerSelfId=n1
sendMessageThreadPoolNums=16
broker-n2.conf
brokerClusterName = RaftCluster
brokerName=RaftNode00
listenPort=30921
namesrvAddr=192.168.56.200:9876
storePathRootDir=/tmp/rmqstore/node01
storePathCommitLog=/tmp/rmqstore/node01/commitlog
enableDLegerCommitLog=true
dLegerGroup=RaftNode00
dLegerPeers=n0-192.168.56.201:40911;n1-192.168.56.202:40912;n2-192.168.56.203:40913
## must be unique
dLegerSelfId=n2
sendMessageThreadPoolNums=16
⑥将主机1上修改好的roocket-mq目录拷贝到其他3台机子上
scp -r rocketmq-all-4.7.0-bin-release root@192.168.56.201:/home/software/
scp -r rocketmq-all-4.7.0-bin-release root@192.168.56.202:/home/software/
scp -r rocketmq-all-4.7.0-bin-release root@192.168.56.203:/home/software/
⑦在主1上启动一个nameserver
sh bin/mqnamesrv
⑧在其他三台主机上启动broker分别使用 broker-n0 、n1、n2
主机2:
sh bin/mqbroker -c conf/dledger/broker-n0.conf
主机3:
sh bin/mqbroker -c conf/dledger/broker-n1.conf
主机4:
sh bin/mqbroker -c conf/dledger/broker-n2.conf
⑧通过可视化控制台查看配置结果<br />![image.png](https://cdn.nlark.com/yuque/0/2020/png/1609516/1593503821029-f218e71f-6f5c-41bc-970f-039ce4c951ee.png#align=left&display=inline&height=28&margin=%5Bobject%20Object%5D&name=image.png&originHeight=55&originWidth=550&size=6693&status=done&style=none&width=275)修改并启动(指定nameserver为 192.168.56.200主机1)<br />![image.png](https://cdn.nlark.com/yuque/0/2020/png/1609516/1593504716132-9e80f584-74df-4c57-89ff-044b410d50d4.png#align=left&display=inline&height=245&margin=%5Bobject%20Object%5D&name=image.png&originHeight=489&originWidth=1089&size=135416&status=done&style=none&width=544.5)<br />⑨将主机4 ctrl+c 模拟宕机<br />![image.png](https://cdn.nlark.com/yuque/0/2020/png/1609516/1593504762635-7e32b315-4339-44e1-98c1-2c6b0e5c7daf.png#align=left&display=inline&height=139&margin=%5Bobject%20Object%5D&name=image.png&originHeight=277&originWidth=903&size=31958&status=done&style=none&width=451.5)
3.2主2从异步复制集群的搭建
1.环境准备:
本机windows启动nameserver、四台虚拟机1、3组成主从,2,4组成主从
windows:192.168.56.1
虚拟机1:192.168.56.200
虚拟机2:192.168.56.201
虚拟机3:192.168.56.202
虚拟机4:192.168.56.203
2.搭建结果图
3.搭建步骤
①在 windows上启动nameserver
②在4台虚拟机上分别启动broker就好,不用做任何配置
虚拟机1:192.168.56.200 作为master启动
sh bin/mqbroker -c conf/2m-2s-async/broker-a.properties -n 192.168.56.1:9876
虚拟机3:192.168.56.202作为虚拟机1的slave启动
sh bin/mqbroker -c conf/2m-2s-async/broker-a-s.properties -n 192.168.56.1:9876
虚拟机2:192.168.56.201作为master启动
sh bin/mqbroker -c conf/2m-2s-async/broker-b.properties -n 192.168.56.1:9876
虚拟机4:192.168.56.203作为虚拟机2的slave启动
sh bin/mqbroker -c conf/2m-2s-async/broker-b-s.properties -n 192.168.56.1:9876
4.2主2从同步复制集群搭建
同3一样就是配置文件使用 2m-2s-sync目录下的配置就好。