1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        CentOS7中使用systemctl列出啟動(dòng)失敗的服務(wù)

        共 3956字,需瀏覽 8分鐘

         ·

        2020-08-04 19:22



        點(diǎn)擊「閱讀原文」查看良許原創(chuàng)精品視頻。

        本教程介紹如何使用systemctl工具列出啟動(dòng)失敗的systemd管理的各個(gè)服務(wù)。文內(nèi)含長(zhǎng)段代碼可復(fù)制可往左滑,希望對(duì)大家有幫助!


        列出啟動(dòng)失敗的服務(wù)

        [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'.
        <以上代碼可復(fù)制粘貼,可往左滑>


        可以發(fā)現(xiàn),有個(gè)一個(gè)服務(wù)啟動(dòng)失敗了。


        is-failed選項(xiàng)


        可以使用is-failed選項(xiàng)檢查指定的服務(wù)是否啟動(dòng)失敗。如果啟動(dòng)失敗,結(jié)果是failed。如果啟動(dòng)沒有問題,結(jié)果是active。


        [root@localhost?~]#?systemctl?is-failed?httpd
        failed
        [root@localhost?~]#?systemctl?is-failed?vsftpd
        active
        <以上代碼可復(fù)制粘貼,可往左滑>

        檢查服務(wù)的狀態(tài)


        可以使用status選項(xiàng),查看服務(wù)啟動(dòng)失敗的原因,下面狀態(tài)信息里面告訴我們,是httpd.conf配置文件354行有語(yǔ)法錯(cuò)誤。


        May?26?09:22:05?localhost?httpd[2958]:?httpd:?Syntax?error?on?line?354?of?/etc/httpd/conf/httpd.conf:?/...osed.
        <以上代碼可復(fù)制粘貼,可往左滑>
        [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.
        <以上代碼可復(fù)制粘貼,可往左滑>



        使用journalctl查看服務(wù)的啟動(dòng)日志

        如果使用systemctl status [unit]沒有找到服務(wù)啟動(dòng)失敗的原因,可以使用journalctl查看更多的啟動(dòng)日志。

        下面操作是過濾出所有帶有error的行,可以找到啟動(dòng)失敗的服務(wù)。


        [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.
        <以上代碼可復(fù)制粘貼,可往左滑>



        也可以使用journalctl -u [unit]只查看某一個(gè)服務(wù)的啟動(dòng)日志:
        [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.

        #過濾出有錯(cuò)誤的信息。
        [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.
        <以上代碼可復(fù)制粘貼,可往左滑>


        發(fā)現(xiàn)?/etc/httpd/conf/httpd.conf配置文件的354行,Directory標(biāo)簽沒有關(guān)閉,返現(xiàn)原因了,就馬上修改吧。


        總? ? 結(jié)


        我們學(xué)習(xí)了如何使用systemctl命令顯示在Linux上運(yùn)行失敗的服務(wù)/單元。有關(guān)詳細(xì)信息,請(qǐng)查看systemctl手冊(cè)。


        良許個(gè)人微信


        添加良許個(gè)人微信即送3套程序員必讀資料


        → 精選技術(shù)資料共享

        → 高手如云交流社群





        本公眾號(hào)全部博文已整理成一個(gè)目錄,請(qǐng)?jiān)诠娞?hào)里回復(fù)「m」獲??!

        推薦閱讀:

        想自己搭建服務(wù)器,永久運(yùn)行網(wǎng)站?一個(gè)U盤大小的樹莓派就夠了!

        CPU 明明 8 個(gè)核,網(wǎng)卡為啥拼命折騰 1 號(hào)核?

        “kill -9”一時(shí)爽,秋后算賬淚兩行


        5T技術(shù)資源大放送!包括但不限于:C/C++,Linux,Python,Java,PHP,人工智能,單片機(jī),樹莓派,等等。在公眾號(hào)內(nèi)回復(fù)「1024」,即可免費(fèi)獲取??!


        瀏覽 49
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            91av成人 | 国产丰满妻一区二区 | 四虎精品永久在线观看 | 亚洲第一狠人色综合 | 三级黄色软件下载 | 国产品久久久 | 久久免费黄色视频 | 国产乱来╳╳A片视频 | 武侠古典涩友亚洲天堂 | 周妍希脱了衣服裤子内裤内衣写真 |