RocketMQ-初体验RocketMQ(03)_RocketMQ多机集群部署

简介: RocketMQ-初体验RocketMQ(03)_RocketMQ多机集群部署


完成了单节点的RocketMQ的安装 RocketMQ-初体验RocketMQ(02)_单节点RocketMQ的安装 ,我们来搞个2个节点的集群来玩下


环境准备

CentOS7

192.168.18.130 、192.168.18.131


Q: 生产环境,假设你有2台主机,应该如何部署RocketMQ集群更HA一些?

A:

你有 A、B两台主机,

A主机 部署 : broker-a 主节点 和 broker-b 从节点

B主机 部署: broker-b 主节点 和 borker-a 从节点

两台主机互为主备,HA更可靠一些,即使有一台主机,假设B主机 宕机了。 我们的A主机上 仍然还有是 broker-a 主节点 和 broker-b 从节点, 这个时候只是 broker-b 只能提供消费消息的能力了,不能写入了。 还是要比 整个 broker-b cluster 因为主机B的宕机而全部不能提供服务了好。


参考配置

在RocketMQ 安装目录 conf目录下,官方提供了一些参考配置

可以集合自己的场景,到对应的目录下看下官方推荐的配置。


集群搭建

130 : brokera-m brokera-s

131: brokerb-m brokerb-s

broker集群在同一台主机上互为主备 。

每台机器上启动一个namesrv。 两个 broker节点,互为主备,构成一个broker集群。

130主机

broker 配置文件

cp 两个文件出来

broker-m.conf master节点的配置文件

broker-s.conf slave节点的配置文件

broker-m.conf

# 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=DefaultCluster
brokerName=broker‐a
# 0 表示主节点
brokerId=0
# rocketmq‐name服务地址,多个地址用;分开,不配置默认为localhost:9876
namesrvAddr=192.168.18.130:9876;192.168.18.131:9876
deleteWhen=04
fileReservedTime=48
#当前节点角色
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
autoCreateTopicEnable=true
#broker通信端口,默认端口
listenPort=10911
#消息存储根路径
storePathRootDir=/data/rocketmq/store-m

broker-s.conf

# 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=DefaultCluster
brokerName=broker‐a
# 非0 表示从节点
brokerId=1
# rocketmq‐name服务地址,多个地址用;分开,不配置默认为localhost:9876
namesrvAddr=192.168.18.130:9876;192.168.18.131:9876
deleteWhen=04
fileReservedTime=48
#当前节点角色
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
autoCreateTopicEnable=true
#broker通信端口,默认端口
listenPort=10811
#消息存储根路径
storePathRootDir=/data/rocketmq/store-s

主要注意的地方

  • brokerName 主从节点 保持一致
  • brokerId 0 表示主节点,从节点 1,2,3…依次类推
  • namesrvAddr 配置所有 namesrv的地址,多个地址 使用 ; 分开
  • brokerRole 这个要注意 主节点 SYNC_MASTER 或者 ASYNC_MASTER 从节点 SLAVE
  • listenPort 确定端口不要重复占用,否则启动失败

启动namesrv

nohup sh bin/mqnamesrv -n 192.168.18.130:9876& 最好通过-n指定主IP,否则的话有可能在多网卡 或者docker环境下 启动失败

[root@artisan rocketmq-all-4.3.2-bin-release]# pwd
/usr/local/rocketmq/rocketmq-all-4.3.2-bin-release
[root@artisan rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqnamesrv -n 192.168.18.130:9876&
[1] 9236
[root@artisan rocketmq-all-4.3.2-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’
tail -f nohup.out    日志如下:
Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON

查看进程

[root@artisan rocketmq-all-4.3.2-bin-release]# jps |grep -v Jps
9239 NamesrvStartup
[root@artisan rocketmq-all-4.3.2-bin-release]# 

启动broker Master 和 broker Slave

主节点: nohup sh bin/mqbroker -c conf/broker-m.conf & 从节点: nohup sh bin/mqbroker -c conf/broker-s.conf &

[root@artisan rocketmq-all-4.3.2-bin-release]# >nohup.out   
主节点启动 
[root@artisan rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqbroker -c  conf/broker-m.conf &
[2] 9415
[root@artisan rocketmq-all-4.3.2-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’
tailf nohup.out 
The broker[brokerâa, 192.168.18.130:10911] boot success. serializeType=JSON and name server is 192.168.18.130:9876;192.168.18.131:9876
^C^C   
从节点启动 
[root@artisan rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqbroker -c  conf/broker-s.conf &
[3] 9495
[root@artisan rocketmq-all-4.3.2-bin-release]# nohup: ignoring input and appending output to ‘nohup.out’
tailf nohup.out 
The broker[brokerâa, 192.168.18.130:10911] boot success. serializeType=JSON and name server is 192.168.18.130:9876;192.168.18.131:9876
The broker[brokerâa, 192.168.18.130:10811] boot success. serializeType=JSON and name server is 192.168.18.130:9876;192.168.18.131:9876
^C  
 查看进程 
[root@artisan rocketmq-all-4.3.2-bin-release]# jps |grep -v Jps
9239 NamesrvStartup
9419 BrokerStartup
9499 BrokerStartup
[root@artisan rocketmq-all-4.3.2-bin-release]# 

131主机

broker 配置文件

操作同130 , 唯一不同的就是这个 brokerName 。

这里贴下 配置

主节点

[root@artisan conf]# cat broker-m.conf 
# 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=DefaultCluster
brokerName=broker‐b
# 0 表示主节点
brokerId=0
# rocketmq‐name服务地址,多个地址用;分开,不配置默认为localhost:9876
namesrvAddr=192.168.18.130:9876;192.168.18.131:9876
deleteWhen=04
fileReservedTime=48
#当前节点角色
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
autoCreateTopicEnable=true
#broker通信端口,默认端口
listenPort=10911
#消息存储根路径
storePathRootDir=/data/rocketmq/store-m

从节点

[root@artisan conf]# cat broker-s.conf 
# 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=DefaultCluster
brokerName=broker‐b
# 非0 表示从节点
brokerId=1
# rocketmq‐name服务地址,多个地址用;分开,不配置默认为localhost:9876
namesrvAddr=192.168.18.130:9876;192.168.18.131:9876
deleteWhen=04
fileReservedTime=48
#当前节点角色
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
autoCreateTopicEnable=true
#broker通信端口,默认端口
listenPort=10811
#消息存储根路径
storePathRootDir=/data/rocketmq/store-s
[root@artisan conf]# 

启动namesrv

同130

启动broker Master 和 broker Slave

同130


查看集群监控状态

mqadmin clusterlist -n 192.168.18.130:9876

[root@artisan rocketmq-all-4.3.2-bin-release]# sh bin/mqadmin clusterlist -n 192.168.18.130:9876
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
#Cluster Name     #Broker Name            #BID  #Addr                  #Version                #InTPS(LOAD)       #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
DefaultCluster    brokerâa              0     192.168.18.130:10911   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436943.73 0.1331
DefaultCluster    brokerâa              1     192.168.18.130:10811   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436943.73 0.1331
DefaultCluster    brokerâb              0     192.168.18.131:10911   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436943.73 0.1654
DefaultCluster    brokerâb              1     192.168.18.131:10811   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436943.73 0.1654
^C^C^C[root@artisan rocketmq-all-4.3.2-bin-release]# ^C
[root@artisan rocketmq-all-4.3.2-bin-release]# sh bin/mqadmin clusterlist -n 192.168.18.131:9876
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
#Cluster Name     #Broker Name            #BID  #Addr                  #Version                #InTPS(LOAD)       #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
DefaultCluster    brokerâa              0     192.168.18.130:10911   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436943.73 0.1331
DefaultCluster    brokerâa              1     192.168.18.130:10811   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436943.73 0.1331
DefaultCluster    brokerâb              0     192.168.18.131:10911   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436943.73 0.1654
DefaultCluster    brokerâb              1     192.168.18.131:10811   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436943.73 0.1654
[root@artisan rocketmq-all-4.3.2-bin-release]# 

如果碰到了如下错误

[root@artisan bin]# ./mqadmin clusterlist -n 192.168.18.130:9876
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
org.apache.rocketmq.tools.command.SubCommandException: ClusterListSubCommand command failed
  at org.apache.rocketmq.tools.command.cluster.ClusterListSubCommand.execute(ClusterListSubCommand.java:93)
  at org.apache.rocketmq.tools.command.MQAdminStartup.main0(MQAdminStartup.java:132)
  at org.apache.rocketmq.tools.command.MQAdminStartup.main(MQAdminStartup.java:83)
Caused by: org.apache.rocketmq.remoting.exception.RemotingTimeoutException: wait response on the channel <192.168.18.130:9876> timeout, 463(ms)
  at org.apache.rocketmq.remoting.netty.NettyRemotingAbstract.invokeSyncImpl(NettyRemotingAbstract.java:391)
  at org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeSync(NettyRemotingClient.java:374)
  at org.apache.rocketmq.client.impl.MQClientAPIImpl.getBrokerClusterInfo(MQClientAPIImpl.java:1180)
  at org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl.examineBrokerClusterInfo(DefaultMQAdminExtImpl.java:275)
  at org.apache.rocketmq.tools.admin.DefaultMQAdminExt.examineBrokerClusterInfo(DefaultMQAdminExt.java:222)
  at org.apache.rocketmq.tools.command.cluster.ClusterListSubCommand.printClusterBaseInfo(ClusterListSubCommand.java:172)
  at org.apache.rocketmq.tools.command.cluster.ClusterListSubCommand.execute(ClusterListSubCommand.java:88)
  ... 2 more
[root@artisan bin]# ^C   重试几次
[root@artisan bin]# ./mqadmin clusterlist -n 192.168.18.130:9876
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
#Cluster Name     #Broker Name            #BID  #Addr                  #Version                #InTPS(LOAD)       #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
DefaultCluster    broker?a              0     192.168.18.130:10911   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436999.54 0.1360
DefaultCluster    broker?a              1     192.168.18.130:10811   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436999.54 0.1360
DefaultCluster    broker?b              0     192.168.18.131:10911   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436999.54 0.1690
DefaultCluster    broker?b              1     192.168.18.131:10811   V4_3_2                   0.00(0,0ms)         0.00(0,0ms)          0 436999.54 0.1690
[root@artisan bin]#     

可能是mqadmin没能正确的连接进去!网络抖动,这个跟底层netty的连接有关. 多重试几次,一般都没问题。


测试发送和消费消息

[root@artisan rocketmq-all-4.3.2-bin-release]# export NAMESRV_ADDR=192.168.18.131:9876
[root@artisan rocketmq-all-4.3.2-bin-release]# 
[root@artisan rocketmq-all-4.3.2-bin-release]# sh bin/tools.sh  org.apache.rocketmq.example.quickstart.Producer

结果截个图:

测试消费者

[root@artisan rocketmq-all-4.3.2-bin-release]# sh bin/tools.sh  org.apache.rocketmq.example.quickstart.Consumer

运行结果 截个图

是不是希望有个页面可以管理和查看集群信息呢? RocketMQ 提供了 RocketMQ Console ,下篇博文我们来看下如何通过拉取源码来搭建一套本地的RocketMQ Console吧


双机互为主备的配置

刚刚搭建的 是 左边的 ,生产环境更建议使用右侧的部署方式

配置的话 ,仅需要调整 broker-s.conf 中的 brokerName即可

131:

broker-s.conf

130 :

broker-s :

启动后,打开RocketMQConsole 看下,符合部署。


RocketMQ4.3.X配置参数

请移步 RocketMQ4.3.x 史上配置最全详解,没有之一

相关实践学习
消息队列RocketMQ版:基础消息收发功能体验
本实验场景介绍消息队列RocketMQ版的基础消息收发功能,涵盖实例创建、Topic、Group资源创建以及消息收发体验等基础功能模块。
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
相关文章
|
6月前
|
消息中间件 Apache 开发工具
RocketMQ-初体验RocketMQ(08)-IDEA拉取调测RocketMQ源码
RocketMQ-初体验RocketMQ(08)-IDEA拉取调测RocketMQ源码
66 0
|
6月前
|
消息中间件 存储 JSON
RocketMQ-初体验RocketMQ(05)_RocketMQ架构解读
RocketMQ-初体验RocketMQ(05)_RocketMQ架构解读
74 0
|
6月前
|
消息中间件 SQL RocketMQ
RocketMQ-初体验RocketMQ(10)-过滤消息_SQL92表达式筛选消息
RocketMQ-初体验RocketMQ(10)-过滤消息_SQL92表达式筛选消息
148 0
|
6月前
|
消息中间件 Java RocketMQ
RocketMQ-初体验RocketMQ(11)-过滤消息_自定义Java类筛选消息
RocketMQ-初体验RocketMQ(11)-过滤消息_自定义Java类筛选消息
66 0
RocketMQ-初体验RocketMQ(11)-过滤消息_自定义Java类筛选消息
|
6月前
|
消息中间件 存储 RocketMQ
RocketMQ-初体验RocketMQ(09)-广播消息、延时消息、批量消息
RocketMQ-初体验RocketMQ(09)-广播消息、延时消息、批量消息
64 0
|
6月前
|
消息中间件 API RocketMQ
RocketMQ-初体验RocketMQ(07)-使用API操作RocketMQ_顺序消息 ordermessage
RocketMQ-初体验RocketMQ(07)-使用API操作RocketMQ_顺序消息 ordermessage
57 0
|
6月前
|
消息中间件 存储 Java
RocketMQ-初体验RocketMQ(06)-使用API操作RocketMQ ,理解RocketMQ的存储结构
RocketMQ-初体验RocketMQ(06)-使用API操作RocketMQ ,理解RocketMQ的存储结构
196 0
|
消息中间件 中间件 数据库
RocketMQ 事务消息初体验
事务消息是 RocketMQ 的高级特性之一 。这篇文章,笔者会从应用场景、功能原理、实战例子三个模块慢慢为你揭开事务消息的神秘面纱。
5356 8
|
消息中间件 运维 网络协议
rabbitmq 高可用集群部署踩坑
rabbitmq 高可用集群部署踩坑
368 0
|
消息中间件 存储 缓存
RabbitMQ 部署及配置详解(集群部署)
RabbitMQ 部署及配置详解(集群部署)
1218 0
下一篇
无影云桌面