环境:
rocketmq版本:4.7.0
rocketmq二进制包:rocketmq-all-4.7.0-bin-release.zip
系统:linux系统
1. 准备namesrv启动脚本 mqnamesrv.sh【任意路径】
#!/bin/bash
source /etc/profile
workdir="/home/ec2-user/config/mq/rocketmq-all-4.7.0-bin-release"start(){nohup $workdir/bin/mqnamesrv >> $workdir/nameserver.out
}stop(){sh $workdir/bin/mqshutdown namesrv
}case $1 instart)start;;stop)stop;;restart)stopstart;;
esac
2. 准备broker启动脚本 mqbroker.sh 【任意路径】
#!/bin/bash
source /etc/profile
workdir="/home/ec2-user/config/mq/rocketmq-all-4.7.0-bin-release"start(){nohup sh $workdir/bin/mqbroker -n 11.0.70.75:9876 -c $workdir/conf/broker.conf >> $workdir/broker.out
}stop(){sh $workdir/bin/mqshutdown broker
}case $1 instart)start;;stop)stop;;restart)stopstart;;
esac
3. 配置开机自启动文件 vim /usr/lib/systemd/system/mqnamesrv.service
[Unit]Description=RocketMQ Namesrv
Wants=network-online.target
After=network-online.target[Service]
Type=sample
WorkingDirectory=/home/ec2-user/config/mq/rocketmq-all-4.7.0-bin-release
User=root
Group=root
ExecStart=/bin/bash mqnamesrv.sh start
ExecStop=/bin/bash mqnamesrv.sh stop
ExecReload=/bin/bash mqnamesrv.sh restart
Restart=always[Install]
WantedBy=multi-user.target
4. 配置开机自启动文件 vim /usr/lib/systemd/system/mqbroker.service
[Unit]Description=RocketMQ Broker
Wants=network-online.target
After=network-online.target[Service]
Type=sample
WorkingDirectory=/home/ec2-user/config/mq/rocketmq-all-4.7.0-bin-release
User=root
Group=root
ExecStart=/bin/bash mqbroker.sh start
ExecStop=/bin/bash mqbroker.sh stop
ExecReload=/bin/bash mqbroker.sh restart
Restart=always[Install]
WantedBy=multi-user.target
5. 使用systemctl启动
systemctl daemon-reload
systemctl enable mqnamesrv.service
systemctl start mqnamesrv.servicesystemctl enable mqbroker.service
systemctl start mqbroker.service