目录
一 官网下载rocketmq
https://rocketmq.apache.org/dowloading/releases/
这里下载4.9.3版本
二 配置(很重要)
2.1 解压文件及准备工作
新建一个目录,我这里新建如下:
D:\soft\java\RocketMQ\many
将该文件解压至该目录下,如图所示:
然后在rocketmq-4.9.3该文件下新建三个文件夹,分别是:logs myconf store ,如图所示
记住文件目录(这个目录很重要,需要将该目录配置到环境变量中),具体如何配置,前面章节中有介绍,可点击链接:一 windows下安装RocketMQ+可视化页面搭建_易天雨的博客-CSDN博客_rocketmq可视化界面windows
D:\soft\java\RocketMQ\many\rocketmq-4.9.3
2.2 修改日志配置路径
打开三个文件,均做如下操作即可完成替换
2.3 配置重要文件
将如图所示的四个文件全部复制到myconf目录中,同时并在myconf文件夹中新建两个文件,分别为:namesrv1.properties和namesrv2.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
四 启动脚本
针对需要启动复杂问题,我这里提供了脚本启动方式,可按照如下配置,新建文件: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
五 页面查看效果
这里记住可视化页面查看
ok 搭建完毕