CentOS

CentOS 7 设置开机自动启动脚本.

2017-02-08  本文已影响129人  方__子

服务器升级到CentOS7 要设置一个开机启动的脚本...
直接使用 vi /etc/rc.d/rc.local 命令,编辑rc.local文件.
但重新启动后发现没有运行相应的脚本....
cat /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.

大致意思是说这个文件是为了兼容而设置的.

如果要使用开始启动 建议使用systemd来建立自己的服务.

如果一定要使用 使用 chmod +x /etc/rc.d/rc.local 来增加权限进行运行.

即然说了不建议使用.我们就不用了.

使用 systemctl 来进行设置自己的服务 其实也非常简单.

1:编辑启动脚本. autostart.sh

注意 此autostart.sh的前三行一定是:

#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run

具体什么原因:参考:http://blog.chinaunix.net/uid-20521628-id-365862.html

2:把autostart.sh 放到 /etc/init.d/

3:运行:systemctl enable autostart.sh

4:reboot 启动 脚本成功运行.

5:使用systemctl disable autostart.sh 可以关闭启动.

上一篇下一篇

猜你喜欢

热点阅读