RocketMQ简介
RocketMQ是阿里巴巴2016年MQ中间件,使用Java语言开发,在阿里内部,RocketMQ承接了例如“双11”等高并发场景的消息流转,能够处理万亿级别的消息。
RocketMQ 安装
准备工作
下载RocketMQ安装包
rocketmq-all-4.7.1-bin-release.zip
安装RocketMQ
- 解压压缩包
-
RocketMQ 目录简介
bin:启动脚本
- conf:配置文件
- lib:依赖jar包
单机安装
修改rocketmq的配置文件broker.conf
修改NameServer以及Broker的启动内存brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
namesrvAddr = 192.168.137.130:9876
deleteWhen = 04
fileReservedTime = 48
brokerIP1 = ${localhost} # 填自己的虚拟机ip
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
authCreateTopicEnable = true #开启自动创建topic的功能
storePathRootDir=/opt/module/rocketmq-all-4.7.0-bin-release/store # 填自己的rocketmq的位置
storePathCommitLog=/opt/module/rocketmq-all-4.7.0-bin-release/store/commitlog # 填自己的rocketmq的位置
修改NameServer的配置
修改Broker的配置vim bin/runserver.sh
# 将67行左右的配置改成如下
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
vim bin/runbroker.sh
# 将67行左右的配置改成如下
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn256m"
单机启动测试
cd /yourrocketmq/
# 启动namesrv
nohup bin/mqnamesrv -n 192.168.137.130:9876 >nameserver.log 2>&1 &
# 启动broker
nohup bin/mqbroker -n 192.168.137.130:9876 -c conf/broker.conf >broker.log 2>&1 &
# 查看启动进程,看到如下的两个进程启动之后,则rocketmq运行成功
jps
9760 Jps
8981 NamesrvStartup
8985 BrokerStartup
rocketmq集群安装
准备工作
在多台机器上,拷贝配置文件,分别为master配置文件及slave配置文件
第一台机器
broker-m.conf
# 修改broker-m为如下内容
namesrvAddr = 192.168.137.130:9876;192.168.137.131:9876;192.168.137.132:9876
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = SYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true
listenPort = 10911
storePathRootDir = /opt/module/rocketmq-all-4.7.0-bin-release/store-m
broker-s.conf
namesrvAddr = 192.168.137.130:9876;192.168.137.131:9876;192.168.137.132:9876
brokerName = broker-a
brokerId = 1
deleteWhen = 04
fileReservedTime = 48
brokerRole = SLAVE
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true
listenPort = 10811
storePathRootDir = /opt/module/rocketmq-all-4.7.0-bin-release/store-s
对于master的配置文件和slave的配置文件,仅修改 storePathRootDir和 brokerRole 以及监听端口这三个配置,其他配置在同一台机器上无变化
第二台机器
broker-m.conf
namesrvAddr = 192.168.137.130:9876;192.168.137.131:9876;192.168.137.132:9876
brokerName = broker-b
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = SYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true
listenPort = 10911
storePathRootDir = /opt/module/rocketmq-all-4.7.0-bin-release/store-m
broker-s.conf
namesrvAddr = 192.168.137.130:9876;192.168.137.131:9876;192.168.137.132:9876
brokerName = broker-b
brokerId = 1
deleteWhen = 04
fileReservedTime = 48
brokerRole = SLAVE
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true
listenPort = 10811
storePathRootDir = /opt/module/rocketmq-all-4.7.0-bin-release/store-s
对于不同机器的master 和 slave配置文件,仅有 brokerName不同,代表着不同的broker,其他配置均相同。hadoop132的配置与上述相同,不再列出
启动测试(在多台机器上全部执行如下的命令)
# 启动namesrv
nohup bin/mqnamesrv >nameserver.log 2>&1 &
# 启动 broker-master
nohup bin/mqbroker -c conf/broker-m.conf >broker-m.log 2>&1 &
# 启动 broker-slave
nohup bin/mqbroker -c conf/broker-s.conf >broker-s.log 2>&1 &
查看集群状态,此时需要借助rocketmq-console控制台管理工具进行查看
下载rocketmq-console 工具
rocketmq-console
- 下载完成之后,使用idea打开项目,修改其中的配置文件(applicaion.properties)
主要修改 rocketmq.config.namesrvAddr 和 rocketmq.config.dataPath 两个配置
最终的修改结果如下,注意修改 rocketmq.config.dataPath,rocketmq.config.namesrvAddr 为自己的路径即可
server.contextPath=
server.port=8080
#spring.application.index=true
spring.application.name=rocketmq-console
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
logging.config=classpath:logback.xml
#if this value is empty,use env value rocketmq.config.namesrvAddr NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876
rocketmq.config.namesrvAddr=192.168.137.130:9876;192.168.137.131:9876;192.168.137.132:9876
#if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
rocketmq.config.isVIPChannel=
#rocketmq-console's data path:dashboard/monitor
rocketmq.config.dataPath=F:/源码构建/rocketmq-console/data
#set it false if you don't want use dashboard.default true
rocketmq.config.enableDashBoardCollect=true
修改完配置文件之后,修改maven依赖,将rocketmq的版本改成自己下的版本
<properties>
<rocketmq.version>4.7.0</rocketmq.version>
</properties>
运行rocketmq-console,在idea中运行SpringBoot的主启动类
访问 http://localhost:8080/#/cluster 看到如下的 三个集群节点启动成功,则集群搭建成功.且控制台也搭建成功.