Centos二进制安装RocketMQ

1. 下载

官网:http://rocketmq.apache.org/

下载最新版本:https://rocketmq.apache.org/release-notes/2023/09/22/5.1.4

将最新的二进制安装包放到Centos服务器上。

或者:

1
2
cd /usr/local/tools
wget https://mirror.bit.edu.cn/apache/rocketmq/5.1.4/rocketmq-all-5.1.4-bin-release.zip

解压

解压二进制包,修改文件夹名称

1
2
unzip rocketmq-all-5.1.4-bin-release.zip
mv rocketmq-all-5.1.4-bin-release rocketmq

创建目录

1
mkdir -p /usr/local/tools/rocketmq/store/broker-a /usr/local/tools/rocketmq/store/broker-a/consumequeue /usr/local/soft/rocketmq/store/broker-a/commitlog /usr/local/soft/rocketmq/store/broker-a/index /usr/local/tools/rocketmq/broker-a/logs 

修改配置文件

1
2
cd /usr/local/tools/rocketmq/conf
vim broker.conf

增加内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#Broker 对外服务的监听端口
listenPort=10911
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#nameServer地址,分号分割
namesrvAddr=localhost:9876
#存储路径
storePathRootDir=/usr/local/tools/rocketmq/store/broker-a
#commitLog 存储路径
storePathCommitLog=/usr/local/tools/rocketmq/store/broker-a/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/tools/rocketmq/store/broker-a/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/tools/rocketmq/store/broker-a/index
#checkpoint 文件存储路径
storeCheckpoint=/usr/local/tools/rocketmq/store/broker-a/checkpoint
#abort 文件存储路径
abortFile=/usr/local/tools/rocketmq/store/broker-a/abort

在虚拟机有可能因为内存不够而启动失败, 修改bin目录下的runbroker.shrunserver.sh文件,比如把8g改成512m,4g改成256m

启动

依次启动nameserver和broker,这两个命令可以做成alias

1
2
3
cd /usr/local/tools/rocketmq/bin
nohup sh mqnamesrv &
nohup sh ./mqbroker -c /usr/local/tools/rocketmq/conf/broker.conf &

查看日志

启动成功后查看mq动态日志

1
2
tail -f ~/logs/rocketmqlogs/namesrv.log
tail -f ~/logs/rocketmqlogs/broker.log

关闭服务

1
2
3
cd /usr/local/tools/rocketmq/bin
sh mqshutdown namesrv
sh mqshutdown broker