柴少的官方网站 技术在学习中进步,水平在分享中升华

Centos7系统rc.local不起作用问题

这也是一个很小的问题就是记录一下。

Centos6习惯用 /etc/rc.local 文件来开机自启动我们一些服务或者操作了。但是Centos7改了,chkconfig也不能用了。发现定义了/etc/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.

touch /var/lock/subsys/local

#查看Centos7已经写了要chmod +x /etc/rc.d/rc.local 授权一下才会起作用。(/etc/rc.local和/etc/rc.d/rc.local效果一样,看下图就知道为什么了)

图片.png

当然有的时候也可能不成功,比如:

/etc/rc.d/rc.local 文件中的内容格式不正确:

开头少了#!/bin/bash,也是执行不成功的,会提示你格式不对。

当然有的时候还可能蛋疼的不能用,

#systemctl list-units --type=service  #来查看一下所有的开启启动项目里面有没有这个rc-local这个服务。

#systemctl  status rc-local.service #来查看一下当前是怎么个状态

然后:

#systemctl enable rc-local.service

#systemctl start rc-local.service
#手工添加下开机启动或者手工起一下看报错信息。

另外:服务的启动文件是存放在了:/lib/systemd/system/目录下面,如果不记得这个服务的全称可以来这个目录下面看。

作者:忙碌的柴少 分类:解决小问题 浏览:8812 评论:0
留言列表
发表评论
来宾的头像