美文网首页
CentOS7中使用systemctl列出启动失败的服务

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

作者: Mracale | 来源:发表于2021-12-18 16:09 被阅读0次

本教程介绍如何使用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

相关文章

网友评论

      本文标题:CentOS7中使用systemctl列出启动失败的服务

      本文链接:https://www.haomeiwen.com/subject/zpegfrtx.html