方法一:(rc.local)
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权
chmod +x /etc/rc.d/rc.local
2、赋予脚本可执行权限
假设/usr/local/script/autostart.sh是你的脚本路径,给予执行权限
chmod +x /usr/local/script/autostart.sh
3、打开/etc/rc.d/rc.local文件,在末尾增加如下内容
/usr/local/script/autostart.sh
方法二:(chkconfig)(推荐)
1、将脚本移动到/etc/rc.d/init.d目录下
mv /usr/local/script/autostart.sh /etc/rc.d/init.d
2、增加脚本的可执行权限
chmod +x /etc/rc.d/init.d/autostart.sh
3、添加脚本到开机自动启动项目中
cd /etc/rc.d/init.d
chkconfig --add autostart.sh
chkconfig autostart.sh on
chkconfig启动脚本规范 在脚本开头加入下面内容:
#!/bin/sh
#chkconfig:2345 80 90
#decription:autostart
说明:chkonfig后面是启动级别和优先级,description后面是服务描述。如上面脚本意思是,
服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,停止的优先级是10。
优先级范围是0-100,数字越大,优先级越低。
注意:不添加以上内容的话添加启动项时会提示service myservice does not support chkconfig
博客介绍了CentOS系统设置脚本开机自动启动的两种方法。方法一是rc.local,需赋予其和脚本可执行权,并在文件末尾添加内容;方法二是chkconfig,推荐使用,要将脚本移到指定目录,增加可执行权限,再添加到开机自动启动项目中。
3466

被折叠的 条评论
为什么被折叠?



