centos7开机卡在7的界面(centos7-开机启动脚本不执行了)
centos7开机卡在7的界面(centos7-开机启动脚本不执行了)service是通过ExecStart=/etc/rc.d/rc.local start 来启动的,所以这个文件需要有执行权限。可是ls -l 查看到/etc/rc.local是一个软连接连接到当前目录的rc.d/rc.local,接着查看/etc/rc.d/rc.local,发现没有执行权限,那我们就给这个文件执行权限:# the Free Software Foundation; either version 2.1 of the License or## systemd is free software; you can redistribute it and/or modify it# under the terms of the GNU Lesser General Public License as published by
前言在centos7之前,都习惯将自己的程序启动命令添加到/etc/rc.local,可是到centos7上面发现不生效了。难道不兼容了?系统默认应该是装了systemd-sysvcompat来兼容sysv的服务的。
rc-local.Service
在centos7上面默认是使用systemd的,所以rc.local这个文件应该也是通过systemd的service启动的,可以在/usr/lib/systemd/system/rc-local.service找到这个service文件,查看里面的内容:
cat /usr/lib/systemd/system/rc-local.service
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License or
service是通过ExecStart=/etc/rc.d/rc.local start 来启动的,所以这个文件需要有执行权限。可是ls -l 查看到/etc/rc.local是一个软连接连接到当前目录的rc.d/rc.local,接着查看/etc/rc.d/rc.local,发现没有执行权限,那我们就给这个文件执行权限:
chmod x /etc/rc.d/rc.local
开启 rc-local.service 服务:systemctl enable rc-local.service
systemctl start rc-local.service
Systemctl enable rc-loacl.service 不成功?systemctl enable rc-local.service
The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
3) A unit may be started when needed via activation (socket path timer
D-Bus udev scripted systemctl call ...).
提示启动service里面没有install这节的内容。那就给它通过多用户的target启动就可以了。
vim /usr/lib/system/system/rc-local.service
[Install]
WantedBy=multi-user.target
然后再次enable启动服务:
systemctl enable rc-local.service
ln -s '/lib/systemd/system/rc-local.service' '/etc/systemd/system/multi-user.target.wants/rc-local.service'
systemd还是sysv?
systemd用起来还是没有sysv顺手,但是个人感觉centos7还是比较推荐让我们自己去写service文件,而不是去添加到rc.local的文件,毕竟添加到这个文件里面,启动就变成了单线程了。如果是自己写service文件可以根据实际情况,跟一些服务并行启动,提升开机速度。个人观点,你觉得是如何呢?