• 设备
    • 今日
    • 1

    rocketmq 开机启动


    操作系统:Ubuntu18
    实现功能:rocketmq4.8 开机启动


    cat /app/rocketmq-4.8.0/conf/broker.conf
    brokerClusterName = DefaultCluster
    brokerName = broker-a
    brokerId = 0
    deleteWhen = 04
    fileReservedTime = 48
    brokerRole = ASYNC_MASTER
    flushDiskType = ASYNC_FLUSH
    autoCreateTopicEnable=true
    namesrvAddr=192.168.1.112:9876
    brokerIP1=192.168.1.112


    #验证是否启动OK:

    tail -f ~/logs/rocketmqlogs/broker.log


    # 如果启动成功,能看到类似如下的日志:
    2022-05-06 09:18:04 INFO main - The broker[broker-a, 192.168.1.112:10911] boot success. serializeType=JSON and name server is 192.168.1.112:9876

    # 验证生产消息正常
执行如下命令:
    export NAMESRV_ADDR=localhost:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer


    # 能看到类似如下输出

    09:07:45.492 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
    RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0).
    RocketMQLog:WARN Please initialize the logger system properly.
    SendResult [sendStatus=SEND_OK, msgId=7F0000016A587EA987AC1BB54BAD0000, offsetMsgId=C0A8017000002A9F0000000000AC4C0C……

    # 验证消费消息正常
执行如下命令:
    sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
    # 能看到类似如下输出:
    09:12:27.025 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
    Consumer Started.
    ConsumeMessageThread_2 Receive New Messages: [MessageExt [brokerName=broker-a, queueId=0, storeSize=212……


    开机启用服务:

    systemctl enable rocketmq.service

    服务状态:

    systemctl status rocketmq

    启动服务:

    systemctl start rocketmq

    关闭服务:

    systemctl stop rocketmq

    重启服务:

    systemctl restart rocketmq

    配置文件执行权限:

    chmod a+x /etc/init.d/rocketmq

    rcconf 查看是否开机启动



    [*] rocketmq

    [*] 中括号中有个*,代表是开机启动!


    ------



    cat /etc/init.d/rocketmq


    #!/usr/bin/env bash
    #
    ### BEGIN INIT INFO
    # Provides:          rocketmq4.8
    # Required-Start:    $remote_fs $syslog
    # Required-Stop:     $remote_fs $syslog
    # Should-Start:      $network $time
    # Should-Stop:       $network $time
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Start rocketmq at boot time
    # Description:       rocketmq - this script starts and stops the rocketmq daemon
    ### END INIT INFO
     
    ROCKETMQ_HOME=/app/rocketmq-4.8.0
    ROCKETMQ_BIN=${ROCKETMQ_HOME}/bin
    ADDR=`hostname -i`:9876
    #ADDR=192.168.1.112: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 ${ROCKETMQ_HOME}/conf/broker.conf > ${BROKER_LOG} 2>&1 &
    echo -n "The broker[ ${ADDR}] boot success..."
    nohup java -jar ./rocketmq-console-ng-2.0.0.jar >> ${ROCKETMQ_HOME}/logs/console.log 2>&1 &
    echo -n "The Console server boot success..."
    }
    
    stop() {
    #stop broker
    cd ${ROCKETMQ_HOME}
    sh bin/mqshutdown broker > ${BROKER_LOG} 2>&1 &
    sleep 1
    #stop namesrv
    sh bin/mqshutdown namesrv > ${NAMESERVER_LOG} 2>&1 &
    #stop console
    PROCESS_NAME="rocketmq-console-ng-2.0"
    CUR_USER=`whoami`
    ps -ef | grep ${PROCESS_NAME} | grep ${CUR_USER} | grep -v grep | awk '{print $2}' | while read pid
    do
            kill -9 ${pid} 2>&1 >/dev/null
            echo "PROCESS:${PROCESS_NAME},PID:${pid} Successfully stopped"
    done
    }
    
    restart() {
    stop
    sleep 5
    start
    }
     
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    restart
    ;;
    *)
    echo $"Usage: $0 {start|stop|restart}"
    exit 2
    esac




    来自:PC 广东省广州市
    上一篇: yearning开机启动
    您可能还喜欢这些:

    1 1条评论

    评论审核已开启:即评论经审核才能正常显示! 记住我的个人信息 回复后邮件通知我