linux开机自动执行脚本

centos7 为例

一 编写脚本后开机执行

在 /etc/rc.d/rc.local 添加可执行脚本的方法未能成功,以前在centos6下是可以的,具体原因未查明,先给出另一种方法添加开机自动运行脚本的方法

1 编写脚本如下

#!/bin/sh
#chkconfig: 2345 80 90
#description:开机自动启动的脚本程序

 # 开启nginx服务
/usr/local/sbin/nginx
/usr/local/php/sbin/php-fpm

脚本第一行 “#!/bin/sh” 告诉系统使用的shell;
脚本第二行 “#chkconfig: 2345 80 90” 表示在2/3/4/5运行级别启动,启动序号(S80),关闭序号(K90);
脚本第三行 表示的是服务的描述信息

2. 将写好的autos.sh脚本移动到/etc/rc.d/init.d/目录下,并给与可执行权限

3 .添加到本机开机启动选项中

chkconfig --add autostart.sh
chkconfig autostart.sh on

二 直接编辑文件

vi /etc/rc.d/rc.local 

添加  /usr/local/nginx/sbin/nginx

chmod +x /etc/rc.d/rc.local

你可能感兴趣的:(linux开机自动执行脚本)