三 windows搭建rocketmq集群(双主双从)

目录

一 官网下载rocketmq

二 配置(很重要)

2.1 解压文件及准备工作

2.2 修改日志配置路径

2.3 配置重要文件

三 启动mq

四 启动脚本

五 页面查看效果


 

 

一 官网下载rocketmq

https://rocketmq.apache.org/dowloading/releases/

这里下载4.9.3版本

bcb27fcaef674d69b3550b8a2cb00532.png

二 配置(很重要)

2.1 解压文件及准备工作

        新建一个目录,我这里新建如下:

        D:\soft\java\RocketMQ\many

        将该文件解压至该目录下,如图所示:

        然后在rocketmq-4.9.3该文件下新建三个文件夹,分别是:logs  myconf  store ,如图所示

3cffb8543fea42e7be1243332bb82d8f.png

记住文件目录(这个目录很重要,需要将该目录配置到环境变量中),具体如何配置,前面章节中有介绍,可点击链接:一 windows下安装RocketMQ+可视化页面搭建_易天雨的博客-CSDN博客_rocketmq可视化界面windows

D:\soft\java\RocketMQ\many\rocketmq-4.9.3

2.2 修改日志配置路径

535c75d0221f4c83aae33584551afd14.png

 打开三个文件,均做如下操作即可完成替换 

43fc14069d2242a3b2191ccdccadaff4.png

2.3 配置重要文件

d2a2366215554a78929029c19df95d1f.png        将如图所示的四个文件全部复制到myconf目录中,同时并在myconf文件夹中新建两个文件,分别为:namesrv1.propertiesnamesrv2.properties,设置端口号,如下

namesrv1.properties文件中内容为:listenPort=9876

namesrv2.properties文件中内容为:listenPort=9877

        修改刚才复制的4个文件(直接复制以下内容全覆盖,具体内容可回去慢慢研究):如下:

broker-a.properties

    #所属集群名字
    brokerClusterName=rocketmq-cluster
    #broker名字,名字可重复,为了管理,每个master起一个名字,他的slave同他,eg:Amaster叫broker-a,他的slave也叫broker-a
    brokerName=broker-a
    #0 表示 Master,>0 表示 Slave
    brokerId=0
    #nameServer地址,分号分割
    namesrvAddr=127.0.0.1:9876;127.0.0.1:9877
    #在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
    defaultTopicQueueNums=4
    #是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
    autoCreateTopicEnable=true
    #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
    autoCreateSubscriptionGroup=true
    #Broker 对外服务的监听端口,
    listenPort=10911
    #删除文件时间点,默认凌晨 4点
    deleteWhen=04
    #文件保留时间,默认 48 小时
    fileReservedTime=120
    #commitLog每个文件的大小默认1G
    mapedFileSizeCommitLog=1073741824
    #ConsumeQueue每个文件默认存30W条,根据业务情况调整
    mapedFileSizeConsumeQueue=300000
    #destroyMapedFileIntervalForcibly=120000
    #redeleteHangedFileInterval=120000
    #检测物理文件磁盘空间
    diskMaxUsedSpaceRatio=88
    #存储路径
    storePathRootDir=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master1/broker-a
    #commitLog 存储路径
    storePathCommitLog=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master1/broker-a/commitlog
    #消费队列存储路径存储路径
    storePathConsumeQueue=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master1/broker-a/consumequeue
    #消息索引存储路径
    storePathIndex=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master1/broker-a/index
    #checkpoint 文件存储路径
    storeCheckpoint=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master1/checkpoint
    #abort 文件存储路径
    abortFile=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master1/abort
    #限制的消息大小
    maxMessageSize=65536
    #flushCommitLogLeastPages=4
    #flushConsumeQueueLeastPages=2
    #flushCommitLogThoroughInterval=10000
    #flushConsumeQueueThoroughInterval=60000
    #Broker 的角色
    #- ASYNC_MASTER 异步复制Master
    #- SYNC_MASTER 同步双写Master
    #- SLAVE
    brokerRole=ASYNC_MASTER
    #刷盘方式
    #- ASYNC_FLUSH 异步刷盘
    #- SYNC_FLUSH 同步刷盘
    flushDiskType=ASYNC_FLUSH
    #checkTransactionMessageEnable=false
    #发消息线程池数量
    #sendMessageThreadPoolNums=128
    #拉消息线程池数量
    #pullMessageThreadPoolNums=128

broker-a-s.properties内容


    #所属集群名字
    brokerClusterName=rocketmq-cluster
    #broker名字,名字可重复,为了管理,每个master起一个名字,他的slave同他,eg:Amaster叫broker-a,他的slave也叫broker-a
    brokerName=broker-a-s
    #0 表示 Master,>0 表示 Slave
    brokerId=1
    #nameServer地址,分号分割
    namesrvAddr=127.0.0.1:9876;127.0.0.1:9877
    #在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
    defaultTopicQueueNums=4
    #是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
    autoCreateTopicEnable=true
    #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
    autoCreateSubscriptionGroup=true
    #Broker 对外服务的监听端口,
    listenPort=10921
    #删除文件时间点,默认凌晨 4点
    deleteWhen=04
    #文件保留时间,默认 48 小时
    fileReservedTime=120
    #commitLog每个文件的大小默认1G
    mapedFileSizeCommitLog=1073741824
    #ConsumeQueue每个文件默认存30W条,根据业务情况调整
    mapedFileSizeConsumeQueue=300000
    #destroyMapedFileIntervalForcibly=120000
    #redeleteHangedFileInterval=120000
    #检测物理文件磁盘空间
    diskMaxUsedSpaceRatio=88
    #存储路径
    storePathRootDir=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave1/broker-a-s
    #commitLog 存储路径
    storePathCommitLog=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave1/broker-a-s/commitlog
    #消费队列存储路径存储路径
    storePathConsumeQueue=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave1/broker-a-s/consumequeue
    #消息索引存储路径
    storePathIndex=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave1/broker-a-s/index
    #checkpoint 文件存储路径
    storeCheckpoint=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave1/checkpoint
    #abort 文件存储路径
    abortFile=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave1/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

broker-b.properties内容


    #所属集群名字
    brokerClusterName=rocketmq-cluster
    #broker名字,名字可重复,为了管理,每个master起一个名字,他的slave同他,eg:Amaster叫broker-a,他的slave也叫broker-a
    brokerName=broker-b
    #0 表示 Master,>0 表示 Slave
    brokerId=0
    #nameServer地址,分号分割
    namesrvAddr=127.0.0.1:9876;127.0.0.1:9877
    #在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
    defaultTopicQueueNums=4
    #是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
    autoCreateTopicEnable=true
    #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
    autoCreateSubscriptionGroup=true
    #Broker 对外服务的监听端口,
    listenPort=10941
    #删除文件时间点,默认凌晨 4点
    deleteWhen=04
    #文件保留时间,默认 48 小时
    fileReservedTime=120
    #commitLog每个文件的大小默认1G
    mapedFileSizeCommitLog=1073741824
    #ConsumeQueue每个文件默认存30W条,根据业务情况调整
    mapedFileSizeConsumeQueue=300000
    #destroyMapedFileIntervalForcibly=120000
    #redeleteHangedFileInterval=120000
    #检测物理文件磁盘空间
    diskMaxUsedSpaceRatio=88
    #存储路径
    storePathRootDir=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master2/broker-b
    #commitLog 存储路径
    storePathCommitLog=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master2/broker-b/commitlog
    #消费队列存储路径存储路径
    storePathConsumeQueue=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master2/broker-b/consumequeue
    #消息索引存储路径
    storePathIndex=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master2/broker-b/index
    #checkpoint 文件存储路径
    storeCheckpoint=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master2/checkpoint
    #abort 文件存储路径
    abortFile=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/master2/abort
    #限制的消息大小
    maxMessageSize=65536
    #flushCommitLogLeastPages=4
    #flushConsumeQueueLeastPages=2
    #flushCommitLogThoroughInterval=10000
    #flushConsumeQueueThoroughInterval=60000
    #Broker 的角色
    #- ASYNC_MASTER 异步复制Master
    #- SYNC_MASTER 同步双写Master
    #- SLAVE
    brokerRole=ASYNC_MASTER
    #刷盘方式
    #- ASYNC_FLUSH 异步刷盘
    #- SYNC_FLUSH 同步刷盘
    flushDiskType=ASYNC_FLUSH
    #checkTransactionMessageEnable=false
    #发消息线程池数量
    #sendMessageThreadPoolNums=128
    #拉消息线程池数量
    #pullMessageThreadPoolNums=128


 

broker-b-s.properties


    #所属集群名字
    brokerClusterName=rocketmq-cluster
    #broker名字,名字可重复,为了管理,每个master起一个名字,他的slave同他,eg:Amaster叫broker-a,他的slave也叫broker-a
    brokerName=broker-b-s
    #0 表示 Master,>0 表示 Slave
    brokerId=1
    #nameServer地址,分号分割
    namesrvAddr=127.0.0.1:9876;127.0.0.1:9877
    #在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
    defaultTopicQueueNums=4
    #是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
    autoCreateTopicEnable=true
    #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
    autoCreateSubscriptionGroup=true
    #Broker 对外服务的监听端口,
    listenPort=10951
    #删除文件时间点,默认凌晨 4点
    deleteWhen=04
    #文件保留时间,默认 48 小时
    fileReservedTime=120
    #commitLog每个文件的大小默认1G
    mapedFileSizeCommitLog=1073741824
    #ConsumeQueue每个文件默认存30W条,根据业务情况调整
    mapedFileSizeConsumeQueue=300000
    #destroyMapedFileIntervalForcibly=120000
    #redeleteHangedFileInterval=120000
    #检测物理文件磁盘空间
    diskMaxUsedSpaceRatio=88
    #存储路径
    storePathRootDir=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave2/broker-b-s
    #commitLog 存储路径
    storePathCommitLog=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave2/broker-b-s/commitlog
    #消费队列存储路径存储路径
    storePathConsumeQueue=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave2/broker-b-s/consumequeue
    #消息索引存储路径
    storePathIndex=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave2/broker-b-s/index
    #checkpoint 文件存储路径
    storeCheckpoint=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave2/checkpoint
    #abort 文件存储路径
    abortFile=D:/soft/java/RocketMQ/many/rocketmq-4.9.3/store/slave2/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

至此,全部配置完毕

三 启动mq

        进入bin目录,cmd进入运行窗口:

// 启动端口号

.\mqnamesrv.cmd -c ..\myconf\namesrv1.properties

.\mqnamesrv.cmd -c ..\myconf\namesrv2.properties

// 启动配置

.\mqbroker.cmd -c ..\myconf\broker-a.properties

.\mqbroker.cmd -c ..\myconf\broker-a-s.properties

.\mqbroker.cmd -c ..\myconf\broker-b.properties

.\mqbroker.cmd -c ..\myconf\broker-b-s.properties

812906be72ed4550b217082b8b2e519f.png

 1cb89fa8b81749e9ae5895f400df8758.png

四 启动脚本

        针对需要启动复杂问题,我这里提供了脚本启动方式,可按照如下配置,新建文件:start_mq.cmd,注意,后缀一定为cmd,即可一键启动,脚本内容如下:

# 启动端口号
set path=D:\soft\java\RocketMQ\many\rocketmq-4.9.3
start %path%\bin\mqnamesrv.cmd -c %path%\myconf\namesrv1.properties
start %path%\bin\mqnamesrv.cmd -c %path%\myconf\namesrv2.properties


# 启动配置
start %path%\bin\mqbroker.cmd -c %path%\myconf\broker-a.properties
start %path%\bin\mqbroker.cmd -c %path%\myconf\broker-a-s.properties
start %path%\bin\mqbroker.cmd -c %path%\myconf\broker-b.properties
start %path%\bin\mqbroker.cmd -c %path%\myconf\broker-b-s.properties

五 页面查看效果

这里记住可视化页面查看

3b1accdfbade498bb64b4563df3d5887.png

ok  搭建完毕

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天雨编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值