rabbitmq添加自启动 centos7环境
1.编辑一个启动脚本
[root@xxx ~]# vim /usr/local/rabbitmq/sbin/start_rabbitmq.sh
内容如下(根据自己的实际位置做替换即可)
#!/bin/bash export PATH=$PATH:/usr/local/erlang/bin export HOME=/usr/local/rabbitmq/ /usr/local/rabbitmq/sbin/./rabbitmq-server -detached
这里面需要指定erlang的环境变量,erlang的安装路径(erlang如何安装可以参考我的上一篇rabbitmq安装的文章)
2.给脚本增加可执行权限
chmod +x /usr/local/rabbitmq/sbin/start_rabbitmq.sh
3.编辑 /etc/rc.d/rc.local
vim /etc/rc.d/rc.local
增加第一步创建的脚本
#!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. touch /var/lock/subsys/local #这里是要执行我们的启动脚本 /usr/local/rabbitmq/sbin/start_rabbitmq.sh
然后需要给rc.local增加可执行权限
chmod +x /etc/rc.d/rc.local
最后重启linux系统看是否生效
shutdown -r now