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

可以发现,有个一个服务启动失败了。
is-failed选项
可以使用is-failed选项检查指定的服务是否启动失败。如果启动失败,结果是failed。如果启动没有问题,结果是active。
[root@localhost ~]# systemctl is-failed httpd
failed
[root@localhost ~]# systemctl is-failed vsftpd
active

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

使用journalctl查看服务的启动日志
如果使用systemctl status [unit]没有找到服务启动失败的原因,可以使用journalctl查看更多的启动日志。
下面操作是过滤出所有带有error的行,可以找到启动失败的服务。
journalctl |grep 'error'

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

网友评论