centos7上部署RocketMQ 4.9.4
1.下载地址
https://rocketmq.apache.org/download/
2.上传并解压
unzip rocketmq-all-4.9.4-bin-release.zip
mv rocketmq-all-4.9.4-bin-release rocketmq-4.9.4
3.修改配置文件
RocketMQ 默认的虚拟机内存较大,启动 Broker 或者 NameServer 可能会因为内存不足而导致失败,所以需要编辑如下两个配置文件,修改 JVM 内存大小。
修改bin/runbroker.sh默认JVM 大小
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m"
修改bin/runserver.sh默认JVM 大小
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
vim broker.conf
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
#增加以下这行,IP修改为自己服务器的ip
brokerIP1 = 172.16.3.86
4.添加环境变量
编辑/etc/profile添加以下内容
export ROCKETMQ_HOME=/opt/rocketmq-4.9.4/
export PATH=${ROCKETMQ_HOME}/bin:$PATH
source /etc/profile
5.启动
cd /opt/rocketmq-4.9.4/bin
# 首先启动Name Server
nohup bash mqnamesrv &
# 验证Name Server 是否启动成功
tail -f nohup.out
The Name Server boot success...
# 启动Broker
nohup bash mqbroker -n localhost:9876 &
# 验证Broker是否启动成功,例如Broker的IP为:192.168.1.2,且名称为broker-a
tail -f nohup.out
The broker[VM-4-15-ubuntu, 10.0.4.15:10911] boot success. serializeType=JSON and name server is localhost:9876
# 关闭
bash mqshutdown namesrv
bash mqshutdown broker
6.测试
# 发送消息
cd /opt/rocketmq-4.9.4/bin/
export NAMESRV_ADDR=localhost:9876
bash bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
# 接收消息
export NAMESRV_ADDR=localhost:9876
bash bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer