rocketmq 多主多从异步复制
- 部署任务:在三台机器上部署 rocketmq 集群,集群包含着 3 个节点。
- 各节点信息以及主从配置如下表所示
IP | 节点名 | 主服务配置 | 从服务配置 |
---|---|---|---|
10.188.25.155 | QHJKK-flow1 | broker-a | broker-b-s |
10.188.25.132 | QHJKK-flow2 | broker-b | broker-c-s |
10.188.25.135 | QHJKK-flow3 | broker-c | broker-a-s |
- 安装 rocketmq,以下操作均为在三台机器上同步进行。
- 安装包:rocketmq-all-4.7.0-bin-release.zip
- 创建新用户(客户要求创建一个 qhjk 新用户,并安装在此用户路径下)
- 命令:useradd qhjk
- 命令:passwd qhjk ,修改密码为 QHjk#2022
- 安装过程
- 进入 /home/qhjk/ 用户目录下,新建目录 install,作为 rocketmq 的安装路径(安装目录自行选择和创建)。
- 进入 /home/qhjk/install/ 目录,将 rocketmq 安装包存放在此路径下
- 命令:unzip rocketmq-all-4.7.0-bin-release.zip ,解压安装包,解压后路径:/home/qhjk/install/rocketmq-all-4.7.0/
- 配置 rocketmq 多主多从异步复制,以下操作在10.188.25.155机器上操作。
- 配置文件目录: rocketmq-all-4.7.0/conf/2m-2s-async ,修改 2m-2s-async/ 目录下的配置文件
- 在 2m-2s-async/ 目录下,只有 broker-a.properties、broker-b.properties、broker-a-s.properties broker-b-s.properties 四个配置文件,为了满足三台机器的 rocketmq 集群配置需求,需要进行以下操作。
- 命令:cp broker-a.properties broker-c.properties
- 命令:cp broker-a-s.properties broker-c-s.properties
- 修改这 6 个配置文件,修改内容如下所示
- broker-a.properties
#集群名 brokerClusterName=QHJKMQ-Cluster #broker 名字 brokerName=broker-a #0 表示 Master, >0 表示 Slave brokerId=0 #nameServer 地址,分号分割 namesrvAddr=10.188.25.155:9876;10.188.25.132:9876;10.188.25.135:9876 #在发送消息时,自动创建服务器不存在的 topic,默认创建的队列数 defaultTopicQueueNums=3 #是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭 autoCreateTopicEnable=true #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭 autoCreateSubscriptionGroup=true #Broker 对外服务的监听端口 listenPort=10911 #删除文件时间点,默认凌晨 4 点 deleteWhen=04 #文件保留时间,默认 48 小时 #fileReservedTime=3600 #commitLog 每个文件的大小默认 1G mapedFileSizeCommitLog=1073741824 #ConsumeQueue 每个文件默认存 30W 条,根据业务情况调整 mapedFileSizeConsumeQueue=300000 #destroyMapedFileIntervalForcibly=120000 #redeleteHangedFileInterval=120000 #文件磁盘最大利用率 diskMaxUsedSpaceRatio=88 #存储路径 storePathRootDir=/home/qhjk/install/rocketmq-all-4.7.0/data/store-a #commitLog 存储路径 storePathCommitLog=/home/qhjk/install/rocketmq-all-4.7.0/data/commitlog-a #消费队列存储路径存储路径 storePathConsumeQueue=/home/qhjk/install/rocketmq-all-4.7.0/data/consumequeue-a #限制的消息大小 maxMessageSize=65536 #flushCommitLogLeastPages=4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker 的角色:ASYNC_MASTER 异步复制 Master;SYNC_MASTER 同步双写 Master ;SLAVE brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH
- broker-b-s.proterties
#集群名 brokerClusterName=QHJKMQ-Cluster #broker 名字 brokerName=broker-b #0 表示 Master, >0 表示 Slave brokerId=1 #nameServer 地址,分号分割 namesrvAddr=10.188.25.155:9876;10.188.25.132:9876;10.188.25.135:9876 #在发送消息时,自动创建服务器不存在的 topic,默认创建的队列数 defaultTopicQueueNums=3 #是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭 autoCreateTopicEnable=true #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭 autoCreateSubscriptionGroup=true #Broker 对外服务的监听端口 listenPort=10921 #删除文件时间点,默认凌晨 4 点 deleteWhen=04 #文件保留时间,默认 48 小时 #fileReservedTime=3600 #commitLog 每个文件的大小默认 1G mapedFileSizeCommitLog=1073741824 #ConsumeQueue 每个文件默认存 30W 条,根据业务情况调整 mapedFileSizeConsumeQueue=300000 #destroyMapedFileIntervalForcibly=120000 #redeleteHangedFileInterval=120000 #文件磁盘最大利用率 diskMaxUsedSpaceRatio=88 #存储路径 storePathRootDir=/home/qhjk/install/rocketmq-all-4.7.0/data/store-b-s #commitLog 存储路径 storePathCommitLog=/home/qhjk/install/rocketmq-all-4.7.0/data/commitlog-b-s #消费队列存储路径存储路径 storePathConsumeQueue=/home/qhjk/install/rocketmq-all-4.7.0/data/consumequeue-b-s #限制的消息大小 maxMessageSize=65536 #flushCommitLogLeastPages=4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker 的角色:ASYNC_MASTER 异步复制 Master;SYNC_MASTER 同步双写 Master ;SLAVE brokerRole=SLAVE flushDiskType=ASYNC_FLUSH
- broker-b.properties
#集群名 brokerClusterName=QHJKMQ-Cluster #broker 名字 brokerName=broker-b #0 表示 Master, >0 表示 Slave brokerId=0 #nameServer 地址,分号分割 namesrvAddr=10.188.25.155:9876;10.188.25.132:9876;10.188.25.135:9876 #在发送消息时,自动创建服务器不存在的 topic,默认创建的队列数 defaultTopicQueueNums=3 #是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭 autoCreateTopicEnable=true #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭 autoCreateSubscriptionGroup=true #Broker 对外服务的监听端口 listenPort=10911 #删除文件时间点,默认凌晨 4 点 deleteWhen=04 #文件保留时间,默认 48 小时 #fileReservedTime=3600 #commitLog 每个文件的大小默认 1G mapedFileSizeCommitLog=1073741824 #ConsumeQueue 每个文件默认存 30W 条,根据业务情况调整 mapedFileSizeConsumeQueue=300000 #destroyMapedFileIntervalForcibly=120000 #redeleteHangedFileInterval=120000 #文件磁盘最大利用率 diskMaxUsedSpaceRatio=88 #存储路径 storePathRootDir=/home/qhjk/install/rocketmq-all-4.7.0/data/store-b #commitLog 存储路径 storePathCommitLog=/home/qhjk/install/rocketmq-all-4.7.0/data/commitlog-b #消费队列存储路径存储路径 storePathConsumeQueue=/home/qhjk/install/rocketmq-all-4.7.0/data/consumequeue-b #限制的消息大小 maxMessageSize=65536 #flushCommitLogLeastPages=4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker 的角色:ASYNC_MASTER 异步复制 Master;SYNC_MASTER 同步双写 Master ;SLAVE brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH
- broker-c-s.properties
#集群名 brokerClusterName=QHJKMQ-Cluster #broker 名字 brokerName=broker-c #0 表示 Master, >0 表示 Slave brokerId=1 #nameServer 地址,分号分割 namesrvAddr=10.188.25.155:9876;10.188.25.132:9876;10.188.25.135:9876 #在发送消息时,自动创建服务器不存在的 topic,默认创建的队列数 defaultTopicQueueNums=3 #是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭 autoCreateTopicEnable=true #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭 autoCreateSubscriptionGroup=true #Broker 对外服务的监听端口 listenPort=10921 #删除文件时间点,默认凌晨 4 点 deleteWhen=04 #文件保留时间,默认 48 小时 #fileReservedTime=3600 #commitLog 每个文件的大小默认 1G mapedFileSizeCommitLog=1073741824 #ConsumeQueue 每个文件默认存 30W 条,根据业务情况调整 mapedFileSizeConsumeQueue=300000 #destroyMapedFileIntervalForcibly=120000 #redeleteHangedFileInterval=120000 #文件磁盘最大利用率 diskMaxUsedSpaceRatio=88 #存储路径 storePathRootDir=/home/qhjk/install/rocketmq-all-4.7.0/data/store-c-s #commitLog 存储路径 storePathCommitLog=/home/qhjk/install/rocketmq-all-4.7.0/data/commitlog-c-s #消费队列存储路径存储路径 storePathConsumeQueue=/home/qhjk/install/rocketmq-all-4.7.0/data/consumequeue-c-s #限制的消息大小 maxMessageSize=65536 #flushCommitLogLeastPages=4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker 的角色:ASYNC_MASTER 异步复制 Master;SYNC_MASTER 同步双写 Master ;SLAVE brokerRole=SLAVE flushDiskType=ASYNC_FLUSH
- broker-c.properties
#集群名 brokerClusterName=QHJKMQ-Cluster #broker 名字 brokerName=broker-c #0 表示 Master, >0 表示 Slave brokerId=0 #nameServer 地址,分号分割 namesrvAddr=10.188.25.155:9876;10.188.25.132:9876;10.188.25.135:9876 #在发送消息时,自动创建服务器不存在的 topic,默认创建的队列数 defaultTopicQueueNums=3 #是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭 autoCreateTopicEnable=true #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭 autoCreateSubscriptionGroup=true #Broker 对外服务的监听端口 listenPort=10911 #删除文件时间点,默认凌晨 4 点 deleteWhen=04 #文件保留时间,默认 48 小时 #fileReservedTime=3600 #commitLog 每个文件的大小默认 1G mapedFileSizeCommitLog=1073741824 #ConsumeQueue 每个文件默认存 30W 条,根据业务情况调整 mapedFileSizeConsumeQueue=300000 #destroyMapedFileIntervalForcibly=120000 #redeleteHangedFileInterval=120000 #文件磁盘最大利用率 diskMaxUsedSpaceRatio=88 #存储路径 storePathRootDir=/home/qhjk/install/rocketmq-all-4.7.0/data/store-c #commitLog 存储路径 storePathCommitLog=/home/qhjk/install/rocketmq-all-4.7.0/data/commitlog-c #消费队列存储路径存储路径 storePathConsumeQueue=/home/qhjk/install/rocketmq-all-4.7.0/data/consumequeue-c #限制的消息大小 maxMessageSize=65536 #flushCommitLogLeastPages=4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker 的角色:ASYNC_MASTER 异步复制 Master;SYNC_MASTER 同步双写 Master ;SLAVE brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH
- broker-a-s.properties
#集群名 brokerClusterName=QHJKMQ-Cluster #broker 名字 brokerName=broker-a #0 表示 Master, >0 表示 Slave brokerId=1 #nameServer 地址,分号分割 namesrvAddr=10.188.25.155:9876;10.188.25.132:9876;10.188.25.135:9876 #在发送消息时,自动创建服务器不存在的 topic,默认创建的队列数 defaultTopicQueueNums=3 #是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭 autoCreateTopicEnable=true #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭 autoCreateSubscriptionGroup=true #Broker 对外服务的监听端口 listenPort=10921 #删除文件时间点,默认凌晨 4 点 deleteWhen=04 #文件保留时间,默认 48 小时 #fileReservedTime=3600 #commitLog 每个文件的大小默认 1G mapedFileSizeCommitLog=1073741824 #ConsumeQueue 每个文件默认存 30W 条,根据业务情况调整 mapedFileSizeConsumeQueue=300000 #destroyMapedFileIntervalForcibly=120000 #redeleteHangedFileInterval=120000 #文件磁盘最大利用率 diskMaxUsedSpaceRatio=88 #存储路径 storePathRootDir=/home/qhjk/install/rocketmq-all-4.7.0/data/store-a-s #commitLog 存储路径 storePathCommitLog=/home/qhjk/install/rocketmq-all-4.7.0/data/commitlog-a-s #消费队列存储路径存储路径 storePathConsumeQueue=/home/qhjk/install/rocketmq-all-4.7.0/data/consumequeue-a-s #限制的消息大小 maxMessageSize=65536 #flushCommitLogLeastPages=4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker 的角色:ASYNC_MASTER 异步复制 Master;SYNC_MASTER 同步双写 Master ;SLAVE brokerRole=SLAVE flushDiskType=ASYNC_FLUSH
- broker-a.properties
- 修改好配置后,将这6个配置复制到另外两台机器上的对应文件夹中,覆盖原先的文件。
- 命令
#先删除此目录中下的配置文件,在其余两台机器上进行操作 rm -rf 2m2s-async/ #在10.188.25.155机器上操作,将此机器上的2m2s-async/这个文件夹以及文件夹下的配置文件全部复制到另外两台机器上 scp -r /home/qhjk/install/rocketmq-all-4.7.0/conf/2m2s-async/ root@10.188.25.132:/home/qhjk/install/rocketmq-all-4.7.0/conf/2m2s-async/ scp -r /home/qhjk/install/rocketmq-all-4.7.0/conf/2m2s-async/ root@10.188.25.135:/home/qhjk/install/rocketmq-all-4.7.0/conf/2m2s-async/
- 命令
- 添加环境变量,命令:vim /etc/profile/ ,添加如下两行内容
export ROCKET_MQ=/home/qhjk/install/rocketmq-all-4.7.0 export PATH=$PATH:$ROCKETMQ_HOME/bin
- 在三台机器上都完成了安装及配置文件的修改之后,启动 rocketmq。
- 在10.188.25.155、10.188.25.155、10.188.25.155 三台机器上依次启动 namesrv
# 第一个>指定了日志的输出路径,末尾的&为默认后台运行 nohup sh namesrv > /home/qhjk/install/rocketmq-all-4.7.0/logs/mqnamesrv.log 2>&1 &
- 在10.188.25.155、10.188.25.155、10.188.25.155 三台机器上依次启动 master
# 10.188.25.155启动master需要指定的配置文件是broker-a.properties nohup sh mqbroker -c /home/qhjk/install/rocketmq-all-4.7.0/conf/2m-2s-async/broker-a.properties > /home/qhjk/install/rocketmq-all-4.7.0/logs/mqbroker-a.log 2>&1 & # 10.188.25.132启动master需要指定的配置文件是broker-b.properties nohup sh mqbroker -c /home/qhjk/install/rocketmq-all-4.7.0/conf/2m-2s-async/broker-b.properties > /home/qhjk/install/rocketmq-all-4.7.0/logs/mqbroker-b.log 2>&1 & # 10.188.25.135启动master需要指定的配置文件是broker-c.properties nohup sh mqbroker -c /home/qhjk/install/rocketmq-all-4.7.0/conf/2m-2s-async/broker-c.properties > /home/qhjk/install/rocketmq-all-4.7.0/logs/mqbroker-c.log 2>&1 &
- 在10.188.25.155、10.188.25.155、10.188.25.155 三台机器上依次启动 slave
# 10.188.25.155启动slave需要指定的配置文件是broker-b-s.properties nohup sh mqbroker -c /home/qhjk/install/rocketmq-all-4.7.0/conf/2m-2s-async/broker-b-s.properties > /home/qhjk/install/rocketmq-all-4.7.0/logs/mqbroker-b-s.log 2>&1 & # 10.188.25.132启动slave需要指定的配置文件是broker-c-s.properties nohup sh mqbroker -c /home/qhjk/install/rocketmq-all-4.7.0/conf/2m-2s-async/broker-c-s.properties > /home/qhjk/install/rocketmq-all-4.7.0/logs/mqbroker-c-s.log 2>&1 & # 10.188.25.135启动slave需要指定的配置文件是broker-a-s.properties nohup sh mqbroker -c /home/qhjk/install/rocketmq-all-4.7.0/conf/2m-2s-async/broker-a-s.properties > /home/qhjk/install/rocketmq-all-4.7.0/logs/mqbroker-a-s.log 2>&1 & #如果遇到启动完slave,master或者namesrv进程就自动退出的情况,就详细指定mqbroker的路径,如: #nohup sh /home/qhjk/install/rocketmq-all-4.7.0/bin/mqbroker -c /home/qhjk/install/rocketmq-all-4.7.0/conf/2m-2s-async/broker-b-s.properties > /home/qhjk/install/rocketmq-all-4.7.0/logs/mqbroker-b-s.log 2>&1 &
- 在10.188.25.155、10.188.25.155、10.188.25.155 三台机器上依次启动 slave
- 在10.188.25.155、10.188.25.155、10.188.25.155 三台机器上依次启动 namesrv
- 启动完成后,在三台机器上执行 jps命令,如果出现1个NamesrvStartup、1个Startup、2个BrokerStartup,就证明部署成功。