官方文档
下载指定版本
将下载好的放到服务器并解压
修改启动内存
vim /opt/modules/rocketmq-all-4.5.2-bin-release/bin/runserver.sh
启动nameserver并查看日志
nohup sh bin/mqnamesrv &
tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...
启动broker
nohup sh bin/mqbroker -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log
The broker[%s, 172.30.30.233:10911] boot success...
启动broker这里有坑
如果服务器有多个网卡有可能启动的不是你想要的ip。
进入rocketmq配置目录
cd /opt/modules/rocketmq-all-4.5.2-bin-release/conf
编写配置文件,并写好配置
echo "brokerIP1=10.2.x.x" > broker.properties
mqbroker 启动时通过 -c 加载配置文件
nohup sh bin/mqbroker -n ${namesrvIp}:9876 -c /opt/modules/rocketmq-all-4.5.2-bin-release/conf/broker.properties &
测试
提前设置环境变量:NAMESRV_ADDR
export NAMESRV_ADDR=192.168.0.162:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...
关闭服务
sh mqshutdown namesrv
sh mqshutdown broker
制作启动脚本rocketadmin.sh
#!/usr/bin/env bash
#
# rocketmq - this script starts and stops the rocketmq daemon
#
# chkconfig: - 85 15
ROCKETMQ_HOME=/opt/modules/rocketmq-all-4.5.2-bin-release
ROCKETMQ_BIN=${ROCKETMQ_HOME}/bin
ADDR=192.168.0.162:9876
LOG_DIR=${ROCKETMQ_HOME}/logs
NAMESERVER_LOG=${LOG_DIR}/namesrv.log
BROKER_LOG=${LOG_DIR}/broker.log
start() {
if [ ! -d ${LOG_DIR} ];then
mkdir ${LOG_DIR}
fi
cd ${ROCKETMQ_HOME}
nohup sh bin/mqnamesrv > ${NAMESERVER_LOG} 2>&1 &
echo -n "The Name Server boot success..."
nohup sh bin/mqbroker -n ${ADDR} -c /opt/modules/rocketmq-all-4.5.2-bin-release/conf/broker.properties > ${BROKER_LOG} 2>&1 &
echo -n "The broker[%s, ${ADDR}] boot success..."
}
stop() {
cd ${ROCKETMQ_HOME}
sh bin/mqshutdown broker
sleep 1
sh bin/mqshutdown namesrv
}
restart() {
stop
sleep 5
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 2
esac
开机启动
[root@localhost system]# more /lib/systemd/system/rocket.service
[Unit]
Description=RocketMq
After=network.target
[Service]
Type=forking
ExecStart=/opt/modules/rocketmq-all-4.5.2-bin-release/rocketadmin.sh start
ExecReload=/opt/modules/rocketmq-all-4.5.2-bin-release/rocketadmin.sh restart
ExecStop=/opt/modules/rocketmq-all-4.5.2-bin-release/rocketadmin.sh stop
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable rocket