当前位置: > CentOS > CentOS故障 >

centos 7.1开机/etc/rc.local脚本不执行的问题

时间:2016-12-29 22:52来源:linux.it.net.cn 作者:IT

Centos 7.1中,/etc/rc.local是一个软链接文件、指向的是/etc/rc.d/rc.local

在Centos之前的版本我们都会将一些开机需要执行的命令加入到/etc/rc.local文件中

但笔者今天在Centos 7.1操作系统中同在/etc/rc.local文件中加入了命令,重启后发现并没有执行,于是再次打开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.
 

这次注意到了上面的注释内容,大致意思是rc.local文件是为了兼容性的问题而添加的

与以前的版本引导时的并行执行相比较,这个脚本将不会在其他所有的服务后执行。如果确实需要让它执行的话

即向之前的版本兼容的话,必须执行"chmod +x /etc/rc.d/rc.local"来确保确保这个脚本在引导时执行。

根据注释,我们明白是因为rc.local文件没有x执行权限,笔者也查看了一下rc.local文件的属于,如下

这时,我们给rc.local文件加上执行权限,如下

[root@5201351 ~]# chmod +x /etc/rc.d/rc.local

重启后发现/etc/rc.local文件里的内容能够执行了。

看样子是Centos 版本的升级变迁,/etc/rc.local /etc/rc.d/rc.local正在被弃用的路上。

 



(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容