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从同步复制)。
image.png
此外,RocketMq还提供了一种新的集群搭建方式,Dledger集群搭建,其架构图应该是我下面这幅图所想的。
image.png

2.新集群的搭建

  1. 搭建环境准备

①四台虚拟机、Linux系统
②ip如下

  1. 主机1: 192.168.56.200
  2. 主机2: 192.168.56.201
  3. 主机3: 192.168.56.202
  4. 主机4: 192.168.56.203
  1. 搭建结果图

image.png

  1. 搭建步骤

①主机1上拷贝rocketmq的tar包或zip包
②解压tar或zip包
③进入bin目录修改 runbroker.sh,修改内容如下:
image.png
④修改bin目录下的runserver.sh,修改结果如下:
image.png
⑤进入/conf/dledger 目录修改broker-n0.conf、broker-n1.conf、broker-n2.conf如下所示
broker-n0.conf

  1. brokerClusterName = RaftCluster
  2. brokerName=RaftNode00
  3. listenPort=30911
  4. namesrvAddr=192.168.56.200:9876
  5. storePathRootDir=/tmp/rmqstore/node00
  6. storePathCommitLog=/tmp/rmqstore/node00/commitlog
  7. enableDLegerCommitLog=true
  8. dLegerGroup=RaftNode00
  9. dLegerPeers=n0-192.168.56.201:40911;n1-192.168.56.202:40912;n2-192.168.56.202:40913
  10. ## must be unique
  11. dLegerSelfId=n0
  12. sendMessageThreadPoolNums=16

broker-n1.conf

  1. brokerClusterName = RaftCluster
  2. brokerName=RaftNode00
  3. listenPort=30921
  4. namesrvAddr=192.168.56.200:9876
  5. storePathRootDir=/tmp/rmqstore/node01
  6. storePathCommitLog=/tmp/rmqstore/node01/commitlog
  7. enableDLegerCommitLog=true
  8. dLegerGroup=RaftNode00dLegerPeers=n0-192.168.56.201:40911;n1-192.168.56.202:40912;n2-192.168.56.203:40913
  9. ## must be unique
  10. dLegerSelfId=n1
  11. sendMessageThreadPoolNums=16

broker-n2.conf

  1. brokerClusterName = RaftCluster
  2. brokerName=RaftNode00
  3. listenPort=30921
  4. namesrvAddr=192.168.56.200:9876
  5. storePathRootDir=/tmp/rmqstore/node01
  6. storePathCommitLog=/tmp/rmqstore/node01/commitlog
  7. enableDLegerCommitLog=true
  8. dLegerGroup=RaftNode00
  9. dLegerPeers=n0-192.168.56.201:40911;n1-192.168.56.202:40912;n2-192.168.56.203:40913
  10. ## must be unique
  11. dLegerSelfId=n2
  12. sendMessageThreadPoolNums=16

⑥将主机1上修改好的roocket-mq目录拷贝到其他3台机子上

  1. scp -r rocketmq-all-4.7.0-bin-release root@192.168.56.201:/home/software/
  2. scp -r rocketmq-all-4.7.0-bin-release root@192.168.56.202:/home/software/
  3. scp -r rocketmq-all-4.7.0-bin-release root@192.168.56.203:/home/software/

image.png
⑦在主1上启动一个nameserver

  1. sh bin/mqnamesrv

⑧在其他三台主机上启动broker分别使用 broker-n0 、n1、n2
主机2:

  1. sh bin/mqbroker -c conf/dledger/broker-n0.conf

主机3:

  1. sh bin/mqbroker -c conf/dledger/broker-n1.conf

主机4:

  1. sh bin/mqbroker -c conf/dledger/broker-n2.conf
  1. ⑧通过可视化控制台查看配置结果<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组成主从

  1. windows192.168.56.1
  2. 虚拟机1192.168.56.200
  3. 虚拟机2192.168.56.201
  4. 虚拟机3192.168.56.202
  5. 虚拟机4192.168.56.203

2.搭建结果图
image.png

3.搭建步骤
①在 windows上启动nameserver
image.png
②在4台虚拟机上分别启动broker就好,不用做任何配置
虚拟机1:192.168.56.200 作为master启动

  1. sh bin/mqbroker -c conf/2m-2s-async/broker-a.properties -n 192.168.56.1:9876

虚拟机3:192.168.56.202作为虚拟机1的slave启动

  1. sh bin/mqbroker -c conf/2m-2s-async/broker-a-s.properties -n 192.168.56.1:9876

虚拟机2:192.168.56.201作为master启动

  1. sh bin/mqbroker -c conf/2m-2s-async/broker-b.properties -n 192.168.56.1:9876

虚拟机4:192.168.56.203作为虚拟机2的slave启动

  1. sh bin/mqbroker -c conf/2m-2s-async/broker-b-s.properties -n 192.168.56.1:9876

image.png
③通过控制台访问本机 nameserver
image.png

4.2主2从同步复制集群搭建

同3一样就是配置文件使用 2m-2s-sync目录下的配置就好。