RocketMQ本地集群配置

RocketMQ本地集群配置

更多完整的配置参数参考

修改NameServer默认端口达到本地集群配置

conf目录下新建一个配置文件conf/namesrv.properties,文件内容为:

listenPort=2058

使用 mqnamesrv -c ../conf/namesrv.properties 指定nameserver配置文件,示例:

PS E:\111softwares\rocketmq-all-4.4.0-bin-release\bin> .\mqnamesrv -c ../conf/namesrv.properties
"set java env ok."
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.
load config properties file OK, ../conf/namesrv.properties
The Name Server boot success. serializeType=JSON

配置Broker本地集群

./mqbroker -n localhost:9876 -c ../conf/2m-2s-sync/broker-a.properties

在conf/broker-*.properties配置文件中指定nameserver:

brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable=true
namesrvAddr=localhost:9876;localhost:2058
listenPort=10911

2主2从同步(2m-2s-sync)集群配置

2m-2s-sync目录下:

第一个主从节点

broker-a.properties
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
namesrvAddr=localhost:9876;localhost:2058
listenPort=10911
# 是否允许Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#存储路径
storePathRootDir=/usr/local/rocketmq/store
#commitLog存储路径
storePathCommitLog=/usr/local/rocketmq/store/commitlog
#消费队列存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
# 消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/index
# checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/store/abort
broker-a-s.properties
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
namesrvAddr=localhost:9876;localhost:2058
listenPort=20911
# 是否允许Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#存储路径
storePathRootDir=/usr/local/rocketmq/as/store
#commitLog存储路径
storePathCommitLog=/usr/local/rocketmq/as/store/commitlog
#消费队列存储路径
storePathConsumeQueue=/usr/local/rocketmq/as/store/consumequeue
# 消息索引存储路径
storePathIndex=/usr/local/rocketmq/as/store/index
# checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/as/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/as/store/abort
broker-b.properties
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
namesrvAddr=localhost:9876;localhost:2058
listenPort=30911
# 是否允许Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#存储路径
storePathRootDir=/usr/local/rocketmq/bm/store
#commitLog存储路径
storePathCommitLog=/usr/local/rocketmq/bm/store/commitlog
#消费队列存储路径
storePathConsumeQueue=/usr/local/rocketmq/bm/store/consumequeue
# 消息索引存储路径
storePathIndex=/usr/local/rocketmq/bm/store/index
# checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/bm/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/bm/store/abort
broker-b-s.properties
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
namesrvAddr=localhost:9876;localhost:2058
listenPort=40911
# 是否允许Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#存储路径
storePathRootDir=/usr/local/rocketmq/bs/store
#commitLog存储路径
storePathCommitLog=/usr/local/rocketmq/bs/store/commitlog
#消费队列存储路径
storePathConsumeQueue=/usr/local/rocketmq/bs/store/consumequeue
# 消息索引存储路径
storePathIndex=/usr/local/rocketmq/bs/store/index
# checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/bs/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/bs/store/abort

在bin目录下分别执行,依次启动2主2从集群的Broker:

./mqbroker -n localhost:9876;localhost:2058 -c ../conf/2m-2s-sync/broker-a.properties
./mqbroker -n localhost:9876;localhost:2058 -c ../conf/2m-2s-sync/broker-a-s.properties
./mqbroker -n localhost:9876;localhost:2058 -c ../conf/2m-2s-sync/broker-b.properties
./mqbroker -n localhost:9876;localhost:2058 -c ../conf/2m-2s-sync/broker-b-s.properties
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置 RocketMQ 集群,请执行以下步骤: 1. 安装 Java 环境,并下载 RocketMQ 安装包。 2. 解压 RocketMQ 安装包,进入解压后的目录。 3. 在 conf 目录下创建两个配置文件:broker-a.properties 和 broker-b.properties。这两个文件分别对应两个不同的 Broker 实例。 4. 修 broker-a.properties 和 broker-b.properties 文件的以下配置项: ``` brokerClusterName=MyCluster brokerName=broker-a 或 broker-b brokerId=0 或 1 namesrvAddr=192.168.1.100:9876;192.168.1.101:9876 ``` brokerClusterName:集群名,需要保证唯一性。 brokerName:Broker 实例名,也需要保证唯一性。 brokerId:Broker 实例 ID,需要保证唯一性。 namesrvAddr:NameServer 地址,多个地址用分号隔开。 5. 复制 broker-a.properties 和 broker-b.properties 文件,分别重命名为 broker-a2.properties 和 broker-b2.properties。这两个文件对应的是 Broker 实例的备份。 6. 在 bin 目录下执行以下命令启动 Broker 实例: ``` nohup sh mqbroker -c ../conf/broker-a.properties & nohup sh mqbroker -c ../conf/broker-b.properties & nohup sh mqbroker -c ../conf/broker-a2.properties & nohup sh mqbroker -c ../conf/broker-b2.properties & ``` 7. 检查 Broker 实例的日志,确保它们启动成功。 8. 配置 Producer 和 Consumer,使用 NameServer 的地址进行消息发送和消费。 以上是简单的 RocketMQ 集群配置。如果需要更高的可用性和容错性,可以考虑使用主从模式或者多主模式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值