1. 根目录下编写脚本 rocketmq.sh 

#!/usr/bin/env bash
# rocketmq - this script starts and stops the rocketmq daemon
#
# chkconfig: - 85 15

ROCKETMQ_HOME=/usr/rocketmq
ROCKETMQ_BIN=${ROCKETMQ_HOME}/bin
ADDR=`hostname -i`: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 -e "The Name Server boot success..."
    nohup sh bin/mqbroker -n ${ADDR} autoCreateTopicEnable=true > ${BROKER_LOG} 2>&1 &
    echo -e "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


2. 通过下面一系列命令添加服务 

[root@i- rocketmq]# chmod a+x rocketmq.sh 
[root@i- rocketmq]# sudo mv rocketmq.sh /etc/init.d/rocketmq
[root@i- rocketmq]# chkconfig --add rocketmq

3. 最后就可能通过 service 命令来管理RocketMQ服务了 

启动:service rocketmq start
关闭:service rocketmq stop
重启:service rocketmq restart

4. 如果出现 /usr/bin/env: 'bash\r': No such file or directory 错误,参考 /usr/bin/env: 'bash\r': No such file or directory 







点赞(0) 打赏

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部