RocketMQ入门-搭建RocketMQ集群

RocketMQ集群安装

在上一节*RocketMQ安装*中,已经安装成功了RocketMQ;现在需要将上一节的虚拟机复制两台出来,组件rocketMq的集群。

Tips:复制后的虚拟机,先修改网络配置文件(vim /etc/sysconfig/network-scripts/ifcfg-ens33)中的IP地址(IPADDR),避免重复。并使用systemctl restart network重启网络服务,再使用ifconfig观察IP是否已经修改成功了。

我的集群hosts配置如下:一主两从

192.168.15.14 rocketmq-master01
192.168.15.15 rocketmq-slave01
192.168.15.16 rocketmq-slave02

打算搭建的集群是3个namesrv,2台从节点上的broker互作主从;即3namesrv,4broker。

启动namesrv

在三台服务器的rocket根目录下,手动创建一个log目录来存放日志;分别执行如下命令启动namesrv:

[root@localhost rocketmq-all-4.8.0-bin-release]# nohup sh bin/mqnamesrv  > log/namesrv.log 2>&1 &

启动broker

slave01节点跑的broker有两个:

  • broker-a
  • broker-b的备份

slave02节点跑的broker有两个:

  • broker-b
  • broker-a的备份

slave01

  1. 从rocket根目录进入conf/2m-2s-async配置目录,基于推荐的配置进行修改,我们这个节点只修改broker-a.properites和broker-b-s.properites

    [root@localhost 2m-2s-async]# pwd
    /u01/environment/rocketmq/rocketmq-all-4.8.0-bin-release/conf/2m-2s-async
    
  2. 编辑broker-a.properites,修改brokerClusterName、brokerName、brokerId、namesrvAddr、autoCreateTopicEnable、listenPort、haListenPort、brokerRole字段和有关所有store的配置字段。大概解释这几个字段的作用:

    • brokerClusterName:集群名称,同一个集群名称组成一个集群
    • brokerName:broker的名称,主从名称可一致
    • brokerId:值为0表示Master节点,大于0表示slave从节点
    • namesrvAddr:注册的namesrvAddr,要么用ip:9876来配置,要么用host:9876来配置;多个namesrvAddr使用;分割
    • autoCreateTopicEnable:自动创建topic,线下开启,方便学习测试
    • autoCreateSubscriptionGroup:消费者自动订阅,线下开启,方便学习测试
    • listenPort:启动broker的端口
    • brokerRole:当前broker的角色,从节点值为SLAVE
    • 所有store字段:从节点的所有store目录要和主节点的区别开,这里使用store-s表示从节点的store目录;如果新启动的broker使用的store是已启动的broker的store,则启动报错java.lang.RuntimeException: Lock failed,MQ already started
  3. 编辑broker-b-s.properites,本配置是用于做slave02上跑的broker-b的从节点。修改的参数可以参考主节点,需要注意的如下:

    • listenPort:不与已启动的broker端口冲突
    • brokerName:新启动的broker的名称,是slave02的broker-b的从节点
    • brokerId:修改为1,从节点的brokerId需要大于0
    • 所有store目录:不要与已启动的broker使用的store目录冲突

参考配置内容如下:

broker主节点的配置:

[root@localhost 2m-2s-async]# cat broker-a.properties 
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样,
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=rocketmq-master01:9876;rocketmq-slave01:9876;rocketmq-slave02:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10911
haListenPort=10912
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
 
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SYNC_MASTER
 
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量 
#pullMessageThreadPoolNums=128
##强制指定本机IP,需要根据每台机器进行修改。官方介绍可为空,系统默认自动识别,但多网卡时IP地址可能读取错误
#brokerIP1=192.168.15.15

broker从节点的配置:

[root@localhost 2m-2s-async]# cat broker-b-s.properties 
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样,
brokerName=broker-b
#0 表示 Master,>0 表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=rocketmq-master01:9876;rocketmq-slave01:9876;rocketmq-slave02:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10923
haListenPort=10924
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/rocketmq/store-s
#commitLog 存储路径
storePathCommitLog=/rocketmq/store-s/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/rocketmq/store-s/consumequeue
#消息索引存储路径
storePathIndex=/rocketmq/store-s/index
#checkpoint 文件存储路径
storeCheckpoint=/rocketmq/store-s/checkpoint
#abort 文件存储路径
abortFile=/rocketmq/store-s/abort
#限制的消息大小
maxMessageSize=65536
 
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SLAVE
 
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量 
#pullMessageThreadPoolNums=128
##强制指定本机IP,需要根据每台机器进行修改。官方介绍可为空,系统默认自动识别,但多网卡时IP地址可能读取错误
#brokerIP1=192.168.15.15

启动操作如下:先切换到rocket的根目录下,然后执行如下命令。

[root@localhost rocketmq-all-4.8.0-bin-release]# nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a.properties > log/broker-a.log 2>&1 &
[root@localhost rocketmq-all-4.8.0-bin-release]# nohup sh bin/mqbroker -c conf/2m-2s-async/broker-b-s.properties > log/broker-b-s.log 2>&1 &

slave02

  1. 从rocket根目录进入conf/2m-2s-async配置目录,基于推荐的配置进行修改,我们这个节点只修改broker-b.properites和broker-a-s.properites
  2. broker-b.properites配置可以直接复用slave01中的broker-a.properites,只需要修改其中的brokerName的值为broker-b即可
  3. broker-a-s.properites配置可以直接复用slave01中的broker-b.properites,只需要修改其中的brokerName的值为broker-a-s即可

启动操作如下:先切换到rocket的根目录下,然后执行如下命令。

[root@localhost rocketmq-all-4.8.0-bin-release]# nohup sh bin/mqbroker -c conf/2m-2s-async/broker-b.properties > log/broker-b.log 2>&1 &
[root@localhost rocketmq-all-4.8.0-bin-release]# nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a-s.properties > log/broker-a-s.log 2>&1 &

测试rocketmq集群

  1. 进入rocket根目录下,执行如下命令,观察响应信息是否如下

    [root@localhost rocketmq-all-4.8.0-bin-release]# sh bin/mqadmin clusterList
    RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
    RocketMQLog:WARN Please initialize the logger system properly.
    #Cluster Name     #Broker Name            #BID  #Addr                  #Version                #InTPS(LOAD)       #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
    rocketmq-cluster  broker-a                0     192.168.15.15:10911    V4_8_0                   0.00(0,0ms)         0.00(0,0ms)          0 449559.47 -1.0000
    rocketmq-cluster  broker-a                1     192.168.15.16:10923    V4_8_0                   0.00(0,0ms)         0.00(0,0ms)          0 449559.47 0.0741
    rocketmq-cluster  broker-b                0     192.168.15.16:10911    V4_8_0                   0.00(0,0ms)         0.00(0,0ms)          0 449559.47 -1.0000
    rocketmq-cluster  broker-b                1     192.168.15.15:10923    V4_8_0                   0.00(0,0ms)         0.00(0,0ms)          0 449559.47 0.0741
    [root@localhost rocketmq-all-4.8.0-bin-release]# 
    
  2. 4个broker,两个broker-a和两个broker-b表示启动是成功了的

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值