检查服务是否启动
在RHEL/CentOS 7上,通过使用systemctl命令检查,可以运行systemctl status命令检查服务的运行状态:
$ systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
...
最后一个单词enabled或者disabled会告诉我们服务的状态,在以上的示例中,Apache2 Web 服务器的httpd服务是启用的。
禁用/移除服务
如果要禁用服务,可以使用systemctl disable命令:
$ systemctl disable httpd
rm '/etc/systemd/system/multi-user.target.wants/httpd.service'
$ systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
...
运行systemctl命令将从/etc/systemd/system/*移除服务符号链接,之后服务就不会起作用了。
启用服务
如果要启用服务,可以使用systemctl enable命令:
$ systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
$ systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
...
如果执行了systemctl disable命令移除了服务,之后再运行systemctl enable命令会重新创建这个服务。
检查服务是否启动成功
使用systemctl --failed可以查看启动失败的服务:
$ systemctl --failed
UNIT LOAD ACTIVE SUB DESCRIPTION
kdump.service loaded failed failed Crash recovery kernel arming
php-fpm.service loaded failed failed The PHP FastCGI Process Manager
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
在以上的示例中,kdump和php-fpm启动失败,如果出现这种情况,需要检查一下服务的启动脚本和它所依赖的服务。
参考链接