更新时间:2024-04-23 GMT+08:00
分享

启动RocketMq

  1. 创建rocketmq-namesrv
    # vim /etc/systemd/system/rocketmq-namesrv.service
    [Unit]
    Description=rocketmq-namesrv
    Documentation=http://mirror.bit.edu.cn/apache/rocketmq/
    After=network.target
    [Service]
    Type=sample
    Environment=JAVA_HOME=/opt/jdk1.8.0_131
    User=root
    ExecStart=/opt/rocketmq-4.4.0/bin/mqnamesrv > /data/rocketmq-4.4.0/logs/mqnamesrv.log 2>&1
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    Restart=0
    LimitNOFILE=65536
    [Install]
    WantedBy=multi-user.target
  2. 创建broker-master
    # vim /etc/systemd/system/rocketmq-master.service
    [Unit]
    Description=rocketmq-master
    Documentation=http://mirror.bit.edu.cn/apache/rocketmq/
    After=network.target
    [Service]
    Type=sample
    Environment=JAVA_HOME=/opt/jdk1.8.0_131
    User=root
    ExecStart=/opt/rocketmq-4.4.0/bin/mqbroker -c /opt/rocketmq-4.4.0/conf/broker-master.conf >/data/rocketmq-4.4.0/logs/mqbroker-master.log 2>&1
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    Restart=0
    LimitNOFILE=65536
    [Install]
    WantedBy=multi-user.target
  3. 创建broker-slave
    # vim /etc/systemd/system/rocketmq-slave.service
    [Unit]
    Description=rocketmq-slave
    Documentation=http://mirror.bit.edu.cn/apache/rocketmq/
    After=network.target
    [Service]
    Type=sample
    Environment=JAVA_HOME=/opt/jdk1.8.0_131
    User=root
    ExecStart=/opt/rocketmq-4.4.0/bin/mqbroker -c /opt/rocketmq-4.4.0/conf/broker-slave.conf >/data/rocketmq-4.4.0/logs/mqbroker-slave.log 2>&1
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    Restart=0
    LimitNOFILE=65536
    [Install]
    WantedBy=multi-user.target
  4. 设置开机自启

    由于rocketmq有启动顺序依赖,因此要写入rc

    # vim /etc/rc.d/rc.local
    systemctl start rocketmq-namesrv
    systemctl start rocketmq-master
    systemctl start rocketmq-slave
    图1 设置开机自启
  5. 启动服务

    重新加载systemctl配置

    # systemctl daemon-reload

    启动顺序namesrv -> master -> slave.

    # systemctl start rocketmq-namesrv && systemctl enable rocketmq-namesrv
    # systemctl start rocketmq-master && systemctl enable rocketmq-master
    # systemctl start rocketmq-slave && systemctl enable rocketmq-slave

    如果要停止,顺序与启动顺序相反。

  6. 检查状态
    # systemctl status rocketmq-namesrv
    # systemctl status rocketmq-master
    # systemctl status rocketmq-slave
    图2 检查状态
  7. 看到上面结果,说明启动成功。
  8. 附加:另一种启动方式

    分别启动3个节点的namesrv和broker,启动顺序namesrv ---> broker。

    启动namesrv

    # nohup sh /opt/rocketmq-4.4.0/bin/mqnamesrv > /data/rocketmq-4.4.0/logs/mqnamesrv.log 2>&1 &

    启动broker-master

    # nohup sh /opt/rocketmq-4.4.0/bin/mqbroker -c /opt/rocketmq-4.4.0/conf/broker-master.conf >/data/rocketmq-4.4.0/logs/mqbroker-master.log 2>&1 &

    启动broker-slave

    # nohup sh /opt/rocketmq-4.4.0/bin/mqbroker -c /opt/rocketmq-4.4.0/conf/broker-slave.conf >/data/rocketmq-4.4.0/logs/mqbroker-slave.log 2>&1 &

    停止顺序则与启动顺序相反。

相关文档