你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

rocketmq集群搭建

2021/11/23 16:00:42

    最近趁着双十一整了两个服务器,搭建一个双主双从同步的rocketmq集群。

    因为只有两个服务器(42.193.126.26 : 以下称服务器A, 39.106.211.60 : 以下称服务器B),每台服务器交错搭一个主一个从。

要求:每台服务器需要安装jdk环境。

每台服务器对应的服务端口规划:

服务器名称服务端口
服务器Anameserver9876
BrokerA-master10910
BrokerB-slave10921
服务器Bnameserver9876
BrokerA-slave10911
BrokerB-master10920

下面开始具体操作:

1.本地下载压缩包,上传到两台服务器路径下

下载4.4版本二进制压缩包:https://archive.apache.org/dist/rocketmq/4.4.0/rocketmq-all-4.4.0-bin-release.zip在每台服务器 /usr/local目录下创建rocketmq文件夹

然后把本地的压缩包上传至/usr/local/rocketmq 目录下

2.在服务器A上解压压缩包,配置

使用unzip 解压后,切换到/usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync目录下:

编辑 broker-a.properties

#Broker 对外服务的监听端口
listenPort=10910
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#nameServer地址,分号分割
namesrvAddr=39.106.211.60:9876;42.193.126.26:9876
#存储路径
storePathRootDir=/usr/local/rocketmq/store/broker-a
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/broker-a/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/broker-a/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/broker-a/index
#checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/store/abort

编辑  broker-b-s.properties

#Broker 对外服务的监听端口
listenPort=10921
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#nameServer地址,分号分割
namesrvAddr=39.106.211.60:9876;42.193.126.26:9876
#存储路径
storePathRootDir=/usr/local/rocketmq/store/broker-b-s
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/broker-b-s/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/broker-b-s/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/broker-b-s/index
#checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/store/abort

3.在服务器B上解压压缩包,配置

使用unzip 解压后,切换到/usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync目录下:

编辑 broker-b.properties

#Broker 对外服务的监听端口
listenPort=10920
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#nameServer地址,分号分割
namesrvAddr=39.106.211.60:9876;42.193.126.26:9876
#存储路径
storePathRootDir=/usr/local/rocketmq/store/broker-b
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/broker-b/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/broker-b/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/broker-b/index
#checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/store/abort

编辑 broker-a-s.properties 

#Broker 对外服务的监听端口
listenPort=10911
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#nameServer地址,分号分割
namesrvAddr=39.106.211.60:9876;42.193.126.26:9876
#存储路径
storePathRootDir=/usr/local/rocketmq/store/broker-a-s
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/broker-a-s/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/broker-a-s/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/broker-a-s/index
#checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/store/abort

4.在服务器A上创建文件夹:mkdir -p /usr/local/rocketmq/store/broker-a /usr/local/rocketmq/store/broker-a/consumequeue /usr/local/rocketmq/store/broker-a/commitlog /usr/local/rocketmq/store/broker-a/index /usr/local/rocketmq/logs /usr/local/rocketmq/store/broker-b-s /usr/local/rocketmq/store/broker-b-s/consumequeue /usr/local/rocketmq/store/broker-b-s/commitlog /usr/local/rocketmq/store/broker-b-s/index

5.在服务器B上创建文件夹:mkdir -p /usr/local/rocketmq/store/broker-a-s /usr/local/rocketmq/store/broker-a-s/consumequeue /usr/local/rocketmq/store/broker-a-s/commitlog /usr/local/rocketmq/store/broker-a-s/index /usr/local/rocketmq/logs /usr/local/rocketmq/store/broker-b /usr/local/rocketmq/store/broker-b/consumequeue /usr/local/rocketmq/store/broker-b/commitlog /usr/local/rocketmq/store/broker-b/index

6.在两台服务器上启动NameServer:

启动nameserver
切到安装rocketmq bin文件目录下
nohup sh mqnamesrv>/usr/local/rocketmq/logs/mqnamesrv.log 2>&1 &
查看nameserver是否启动成功
tail -f /usr/local/rocketmq/logs/mqnamesrv.log

7.服务器A启动BrokerServer:

nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-a.properties> /usr/local/rocketmq/logs/broker-a.log 2>&1 &

查看是否启动成功:tail -f /usr/local/rocketmq/logs/cat broker-a.log

nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-b-s.properties> /usr/local/rocketmq/logs/broker-b-s.log 2>&1 &

查看是否启动成功:tail -f /usr/local/rocketmq/logs/cat broker-b-s.log

8.服务器B启动BrokerServer:

nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-a-s.properties> /usr/local/rocketmq/logs/broker-a-s.log 2>&1 &

查看是否启动成功:tail -f /usr/local/rocketmq/logs/cat broker-a-2.log

nohup sh mqbroker -c /usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf/2m-2s-sync/broker-b.properties > /usr/local/rocketmq/logs/broker-b.log 2>&1 &

查看是否启动成功:tail -f /usr/local/rocketmq/logs/cat broker-b.log

------------------------------以上rocketmq集群服务启动完毕--------------------------------

注意:用jps查看每台服务器应该有一个NameServer和两个BrokerServer服务在运行着,表明启动成功;

1.启动过程中可能出现内存不足,需要调整bin目录下的runserver.sh , runbroker.sh中的jvm参数大小

2.停止服务的时候需要注意,要先停止broker,其次停止nameserver。

切换到bin目录下,依次执行如下命令:

sh mqshutdown namesrv
sh mqshutdown broker

-------------------------------以下是安装rocketmq可视化控制台-----------------------------

 1.下载

https://codeload.github.com/apache/rocketmq-externals/zip/refs/heads/release-rocketmq-console-1.0.0

2.修改application.properties

3.打包成jar

mvn clean package -Dmaven.test.skip=true 

4.启动jar

java -jar rocketmq-console-ng-1.0.0.jar

5.访问

​​​​​​​http://42.193.126.26:7928


 

注意启动jar包是可能出现连不上服务,需要在/usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/conf 目录下修改配置文件broker.conf

加上配置项:brokerIP1 = 你服务器的公网ip地址

至此rocketmq双主双从同步的集群搭建成功!