更新时间:2024-04-23 GMT+08:00
启动RocketMq
- 创建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
- 创建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
- 创建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
- 设置开机自启
# vim /etc/rc.d/rc.local systemctl start rocketmq-namesrv systemctl start rocketmq-master systemctl start rocketmq-slave
图1 设置开机自启
- 启动服务
# 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
如果要停止,顺序与启动顺序相反。
- 检查状态
# systemctl status rocketmq-namesrv # systemctl status rocketmq-master # systemctl status rocketmq-slave
图2 检查状态
- 看到上面结果,说明启动成功。
- 附加:另一种启动方式
分别启动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 &
停止顺序则与启动顺序相反。
父主题: Rocketmq部署