CentOS7中使用systemctl列出启动失败的服务

2021-12-18  本文已影响0人  Mracale

本教程介绍如何使用systemctl工具列出启动失败的systemd管理的各个服务

systemctl list-units --state failed
image.png

可以发现,有个一个服务启动失败了。

is-failed选项
可以使用is-failed选项检查指定的服务是否启动失败。如果启动失败,结果是failed。如果启动没有问题,结果是active。

[root@localhost ~]# systemctl is-failed httpd
failed
[root@localhost ~]# systemctl is-failed vsftpd
active
image.png

检查服务的状态
可以使用status选项,查看服务启动失败的原因,下面状态信息里面告诉我们,是httpd.conf配置文件354行有语法错误。

systemctl status httpd
image.png

使用journalctl查看服务的启动日志
如果使用systemctl status [unit]没有找到服务启动失败的原因,可以使用journalctl查看更多的启动日志。

下面操作是过滤出所有带有error的行,可以找到启动失败的服务。

journalctl |grep 'error'
image.png

也可以使用journalctl -u [unit]只查看某一个服务的启动日志:

journalctl -u httpd.service
image.png
上一篇 下一篇

猜你喜欢

热点阅读