創建自啓動腳本:mysql
vi /etc/init.d/rabbitmq
輸入以下內容:sql
#!/bin/bash # # mysql startup script for the RabbitMQ server # # chkconfig: 2345 90 10 # description: start the RabbitMQ # # Source function library . /etc/rc.d/init.d/functions #腳本名稱 prog=rabbitmq #RabbitMQ安裝目錄 RABBITMQ_HOME=/opt/rabbitmq-3.7.14-1 export RABBITMQ_HOME case "$1" in start) echo "Starting RabbitMQ ..." $RABBITMQ_HOME/ctlscript.sh start ;; stop) echo "Stopping RabbitMQ ..." $RABBITMQ_HOME/ctlscript.sh stop ;; restart) echo "Restarting RabbitMQ ..." $RABBITMQ_HOME/ctlscript.sh restart ;; *) echo "Usage: $prog {start|stop|restart}" ;; esac exit 0
跳轉目錄:bash
cd /etc/init.d/
修改文件爲可運行文件:rest
chmod a+x rabbitmq
查看rabbitmq開機啓動狀況:code
chkconfig --list
如沒有,則添加到系統啓動隊列中:server
chkconfig --add rabbitmq
從新檢查RabbitMQ開機啓動狀況,若成功,則應顯示以下內容:rabbitmq
rabbitmq 0:off 1:off 2:on 3:on 4:on 5:on 6:off隊列
使用下列命令對RabbitMQ進行重啓、中止、啓動:ip
service rabbitmq restart/stop/start