CentOS7中使用systemctl列出啟動失敗的服務
本教程介紹如何使用systemctl工具列出啟動失敗的systemd管理的各個服務 |
列出啟動失敗的服務
[root@localhost ~]# systemctl list-units --state failed UNIT LOAD ACTIVE SUB DESCRIPTION ● httpd.service loaded failed failed The Apache HTTP Server 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. 1 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
可以發現,有個一個服務啟動失敗了。
is-failed選項
可以使用
is-failed
選項檢查指定的服務是否啟動失敗。如果啟動失敗,結果是
failed
。如果啟動沒有問題,結果是
active
。
[root@localhost ~]# systemctl is-failed httpd failed [root@localhost ~]# systemctl is-failed vsftpd active
檢查服務的狀態
可以使用
status
選項,檢視服務啟動失敗的原因,下面狀態資訊裡面告訴我們,是
httpd.conf
配置檔案354行有語法錯誤。
May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /...osed.
[root@localhost ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Tue 2020-05-26 09:22:05 CST; 18min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 2958 (code=exited, status=1/FAILURE) May 26 09:22:05 localhost systemd[1]: Starting The Apache HTTP Server... May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /...osed. May 26 09:22:05 localhost systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE May 26 09:22:05 localhost kill[2959]: kill: cannot find process "" May 26 09:22:05 localhost systemd[1]: httpd.service: control process exited, code=exited status=1 May 26 09:22:05 localhost systemd[1]: Failed to start The Apache HTTP Server. May 26 09:22:05 localhost systemd[1]: Unit httpd.service entered failed state. May 26 09:22:05 localhost systemd[1]: httpd.service failed. Hint: Some lines were ellipsized, use -l to show in full.
使用journalctl檢視服務的啟動日誌
如果使用
systemctl status [unit]
沒有找到服務啟動失敗的原因,可以使用journalctl檢視更多的啟動日誌。
下面操作是過濾出所有帶有
error
的行,可以找到啟動失敗的服務。
[root@localhost ~]# journalctl |grep 'error' May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:354:was not closed.
也可以使用
journalctl -u [unit]
只檢視某一個服務的啟動日誌:
[root@localhost ~]# journalctl -u httpd.service -- Logs begin at Sun 2020-05-24 06:52:52 CST, end at Tue 2020-05-26 09:48:03 CST. -- May 26 09:22:05 localhost systemd[1]: Starting The Apache HTTP Server... May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:354:was not closed. May 26 09:22:05 localhost systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE May 26 09:22:05 localhost kill[2959]: kill: cannot find process "" May 26 09:22:05 localhost systemd[1]: httpd.service: control process exited, code=exited status=1 May 26 09:22:05 localhost systemd[1]: Failed to start The Apache HTTP Server. May 26 09:22:05 localhost systemd[1]: Unit httpd.service entered failed state. May 26 09:22:05 localhost systemd[1]: httpd.service failed. #過濾出有錯誤的資訊。 [root@localhost ~]# journalctl -u httpd.service |grep 'error' May 26 09:22:05 localhost httpd[2958]: httpd: Syntax error on line 354 of /etc/httpd/conf/httpd.conf: /etc/httpd/conf/httpd.conf:354:was not closed.
發現
/etc/httpd/conf/httpd.conf
配置檔案的354行,
Directory
標籤沒有關閉,返現原因了,就馬上修改吧。
總結
我們學習瞭如何使用systemctl 顯示在 上執行失敗的服務/單元。有關詳細資訊,請檢視systemctl手冊。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31524109/viewspace-2772685/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux使用Ambari啟動服務啟動失敗Linux
- sqlserver服務啟動失敗-1067SQLServer
- systemctl 命令設定開機自啟動失敗
- systemctl 命令在 Linux 中啟動、停止和重新啟動服務Linux
- 【伺服器】伺服器的服務啟動失敗伺服器
- Linux中如何使用systemctl進行服務的管理?Linux
- linux系統服務(systemctl)的使用Linux
- linux中透過systemctl建立服務並實現開機啟動Linux
- 使用systemctl進行服務管理
- docker啟動失敗Docker
- tomcat 啟動失敗Tomcat
- easyswoole啟動失敗
- sqlplus啟動失敗SQL
- MySQL啟動失敗MySql
- 使用Systemctl命令來管理系統服務
- Win7 Nginx啟動失敗 cmd命令失敗Win7Nginx
- Watt Toolkit 報錯:加速服務啟動失敗,443埠被 svnhttpsvc (4996) 佔用HTTP996
- dubbo啟動多個服務失敗 com.alibaba.dubbo.rpc.RpcException: Fail to start serverRPCExceptionAIServer
- dota2啟動失敗 初始化vulkan失敗
- docker啟動的服務有匯出檔案的功能,檔案一直匯出失敗Docker
- Docker centos7 systemctl命令不能使用DockerCentOS
- mount程式在systemctl守護的情況下,mount dir程式被oom後重新啟動失敗的處理方法OOM
- Oracle RAC啟動失敗(DNS故障)OracleDNS
- 問題一:Kibaba 啟動失敗
- dbsnmp啟動失敗解決方法
- Hadoop 啟動namenode節點失敗Hadoop
- Systemctl幾個操作服務命令
- 【資料庫資料恢復】MongoDB資料庫服務啟動失敗的資料恢復案例資料庫資料恢復MongoDB
- CentOS7中搭建cobbler自動裝機服務CentOS
- mongodb啟動失敗問題解決MongoDB
- mysql(mariadb)啟動失敗解決方法MySql
- hbase啟動失敗問題解決
- httpd使用systemctl啟動超時解決過程httpd
- 使用微服務失敗的11個原因 - Shekhar Gulati微服務
- Oracle RAC啟動失敗-軟連結惹的禍Oracle
- sock鎖檔案導致的MySQL啟動失敗MySql
- vagrant啟動身份驗證失敗的解決方式
- 使用node啟動一個簡單的服務