中间件RocketMQ系列(三)

RocketMQ双主双从集群部署

上一篇中间件RocketMQ系列(一)介绍了单master节点模式的部署,所以本文不再赘述下载上传等步骤

一、环境准备

1.配置文件说明

配置文件目录:/yl/app/rocketmq-5.1.4/conf/

  • 2m-2s-async :双主双从-异步模式的 配置文件(本文选择这种模式)
  • 2m-2s-sync :双主双从 -同步模式 配置文件
  • 2m-noslave:双主,没有从节点模式的 配置文件
cd 2m-2s-async
  • broker-a.properties :主节点a
  • broker-a-s.properties :从节点a
  • broker-b.properties :主节点b
  • broker-b-s.properties:从节点b
2.服务器准备

节点总共所需4个Broker节点,2个NameServer节点,本文使用2台虚拟机不同端口进行模拟

分布如下:

机器A(172.16.82.39)部署Broker-a、Broker-b-s、nameserver-a

机器B(172.16.82.97)部署Broker-b、Broker-a-s、nameserver-b

同一个broker的主从,尽量不要放在同一台服务上,免得当此服务宕机时,主从同时挂掉

3.创建存储路径

机器A(172.16.82.39)、机器B(172.16.82.97)都要创建

mkdir /yl/app/rocketmq-5.1.4/data
4.jdk环境配置参考Linux环境系列(一)
5.配置文件编写

机器A(172.16.82.39):

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名字,注意此处不同的配置文件填写的不一样  例如:在a.properties 文件中写 broker-a  在b.properties 文件中写 broker-b
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#Broker 的角色,ASYNC_MASTER=异步复制Master,SYNC_MASTER=同步双写Master,SLAVE=slave节点
brokerRole=ASYNC_MASTER
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘 
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=10911
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=172.16.82.39:10900;172.16.82.97:10900
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均>衡
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#设置BrokerIP
brokerIP1=172.16.82.39
#存储路径
storePathRootDir=/yl/app/rocketmq-5.1.4/data/store-a
#commitLog 存储路径
storePathCommitLog=/yl/app/rocketmq-5.1.4/data/store-a/commitlog
#消费队列存储路径存储路径
storePathConsumerQueue=/yl/app/rocketmq-5.1.4/data/store-a/consumequeue
#消息索引存储路径
storePathIndex=/yl/app/rocketmq-5.1.4/data/store-a/index
#checkpoint 文件存储路径
storeCheckpoint=/yl/app/rocketmq-5.1.4/data/store-a/checkpoint
#abort 文件存储路径
abortFile=/yl/app/rocketmq-5.1.4/data/store-a/abort
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000

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 lice
### RocketMQ 系列介绍 RocketMQ 是一款分布式消息中间件,最初由阿里巴巴开发并开源。其设计目标是在大规模集群环境中提供高吞吐量、低延迟以及可靠的异步通信能力。 #### 3.4.6 版本特性 在 RocketMQ 3.4.6 中,支持多种角色配置模式来增强系统的可用性和性能优化。例如,在 `brokerRole` 设置为 ASYNC 或 SYNC_MASTER 的情况下可以搭配两个 Slave 实现数据冗余备份[^1]。这种架构不仅提高了读写分离效率还增强了灾难恢复的能力。 #### Consumer 配置灵活性 对于消费者行为控制方面,RocketMQ 提供了灵活的参数调整选项。通过编辑 broker.conf 文件能够自定义消费者的重试机制,包括最大尝试次数与每次等待的时间间隔等重要属性设置[^2]。这些功能使得开发者可以根据具体应用场景微调消费逻辑以满足不同的业务需求。 #### 架构演进 - 从 4.x 到 5.0 随着技术的发展,RocketMQ 不断改进内部结构以适应更广泛的应用场景。到了 4.x 版本时期,客户端可以直接连接到Broker节点完成消息收发操作;而当进入5.0时代之后,则引入了一个名为Proxy的新组件作为中介层存在于两者之间。虽然这种方式可能会带来额外的一次序列化/反序列化进程从而影响响应速度,但对于某些特定环境下的部署方案(比如LOCAL模式),它依然提供了更好的管理和维护便利性[^3]。 #### 对比其他产品线如 SofaMQ 面对市场上众多竞争对手推出的相似服务时,像阿里云旗下的SofaMQ就成为了潜在替代品之一。尽管二者都属于成熟的解决方案范畴内,但在选型过程中仍需考虑诸如团队技能水平差异、现有基础设施兼容程度等多个维度因素来进行综合评判和决策制定[^4]。 ```python # Python 客户端简单示例 (适用于大多数版本) from rocketmq.client import PushConsumer, ConsumeStatus consumer = PushConsumer('your_group_name') consumer.subscribe('TopicTest', 'TagA || TagB || TagC') def callback(msg): print(f"Received message: {msg.body}") return ConsumeStatus.CONSUME_SUCCESS consumer.register_message_listener(callback) try: consumer.start() finally: consumer.shutdown() ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值