{"id":43952,"date":"2024-10-06T11:45:15","date_gmt":"2024-10-06T03:45:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43952\/"},"modified":"2024-10-06T11:45:15","modified_gmt":"2024-10-06T03:45:15","slug":"centos-8-%e9%80%9a%e9%81%8e-journalctl-%e5%88%86%e6%9e%90%e6%97%a5%e8%aa%8c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43952\/","title":{"rendered":"CentOS 8 \u901a\u904e journalctl \u5206\u6790\u65e5\u8a8c"},"content":{"rendered":"<h1 id=\"centos-8-%e9%80%9a%e9%81%8e-journalctl-%e5%88%86%e6%9e%90%e6%97%a5%e8%aa%8c-ArLjWKzpFv\">CentOS 8 \u901a\u904e journalctl \u5206\u6790\u65e5\u8a8c<\/h1>\n<p>\u5728\u4f3a\u670d\u5668\u7ba1\u7406\u4e2d\uff0c\u65e5\u8a8c\u6a94\u6848\u7684\u5206\u6790\u662f\u78ba\u4fdd\u7cfb\u7d71\u7a69\u5b9a\u6027\u548c\u5b89\u5168\u6027\u7684\u91cd\u8981\u6b65\u9a5f\u3002CentOS 8 \u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684 Linux \u767c\u884c\u7248\uff0c\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u65e5\u8a8c\u7ba1\u7406\u5de5\u5177\uff0c\u5176\u4e2d <code>journalctl<\/code> \u662f\u4e00\u500b\u975e\u5e38\u6709\u7528\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u7528\u65bc\u67e5\u770b\u548c\u5206\u6790\u7cfb\u7d71\u65e5\u8a8c\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528 <code>journalctl<\/code> \u4f86\u5206\u6790 CentOS 8 \u7684\u65e5\u8a8c\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-journalctl%ef%bc%9f-ArLjWKzpFv\">\u4ec0\u9ebc\u662f journalctl\uff1f<\/h2>\n<p><code>journalctl<\/code> \u662f\u4e00\u500b\u7528\u65bc\u67e5\u8a62\u548c\u986f\u793a\u7cfb\u7d71\u65e5\u8a8c\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u9019\u4e9b\u65e5\u8a8c\u7531 systemd \u7684\u65e5\u8a8c\u7cfb\u7d71\uff08systemd-journald\uff09\u7ba1\u7406\u3002\u5b83\u80fd\u5920\u96c6\u4e2d\u7ba1\u7406\u4f86\u81ea\u4e0d\u540c\u670d\u52d9\u548c\u61c9\u7528\u7a0b\u5e8f\u7684\u65e5\u8a8c\uff0c\u4e26\u63d0\u4f9b\u9748\u6d3b\u7684\u67e5\u8a62\u9078\u9805\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e7%94%a8%e6%b3%95-ArLjWKzpFv\">\u57fa\u672c\u7528\u6cd5<\/h2>\n<p>\u8981\u4f7f\u7528 <code>journalctl<\/code>\uff0c\u9996\u5148\u9700\u8981\u6253\u958b\u7d42\u7aef\u4e26\u8f38\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>journalctl<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u6240\u6709\u7684\u65e5\u8a8c\u689d\u76ee\uff0c\u5f9e\u6700\u65b0\u7684\u5230\u6700\u820a\u7684\u3002\u70ba\u4e86\u66f4\u597d\u5730\u5206\u6790\u65e5\u8a8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u9078\u9805\u4f86\u904e\u6ffe\u548c\u683c\u5f0f\u5316\u8f38\u51fa\u3002<\/p>\n<h3 id=\"%e5%b8%b8%e7%94%a8%e9%81%b8%e9%a0%85-ArLjWKzpFv\">\u5e38\u7528\u9078\u9805<\/h3>\n<ul>\n<li><code>-b<\/code>: \u986f\u793a\u7576\u524d\u555f\u52d5\u7684\u65e5\u8a8c\u3002<\/li>\n<li>&lt;code&#8211;since &quot;YYYY-MM-DD HH:MM:SS&quot;<\/code>: \u5f9e\u6307\u5b9a\u7684\u6642\u9593\u958b\u59cb\u986f\u793a\u65e5\u8a8c\u3002<\/li>\n<li>&lt;code&#8211;until &quot;YYYY-MM-DD HH:MM:SS&quot;<\/code>: \u76f4\u5230\u6307\u5b9a\u7684\u6642\u9593\u986f\u793a\u65e5\u8a8c\u3002<\/li>\n<li>&lt;code&#8211;priority=PRIORITY<\/code>: \u6839\u64da\u65e5\u8a8c\u7684\u512a\u5148\u7d1a\u904e\u6ffe\u689d\u76ee\uff0c\u4f8b\u5982 <code>err<\/code>\u3001<code>warn<\/code>\u3001<code>info<\/code> \u7b49\u3002<\/li>\n<li>&lt;code&#8211;unit=UNIT_NAME<\/code>: \u53ea\u986f\u793a\u7279\u5b9a\u55ae\u5143\u7684\u65e5\u8a8c\uff0c\u4f8b\u5982 <code>httpd.service<\/code>\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%af%84%e4%be%8b%e5%88%86%e6%9e%90-ArLjWKzpFv\">\u7bc4\u4f8b\u5206\u6790<\/h2>\n<p>\u5047\u8a2d\u6211\u5011\u60f3\u67e5\u770b Apache \u4f3a\u670d\u5668\u7684\u65e5\u8a8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>journalctl --unit=httpd.service<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u8207 Apache \u4f3a\u670d\u5668\u76f8\u95dc\u7684\u6240\u6709\u65e5\u8a8c\u689d\u76ee\u3002\u5982\u679c\u6211\u5011\u53ea\u60f3\u67e5\u770b\u6700\u8fd1\u7684\u65e5\u8a8c\uff0c\u53ef\u4ee5\u52a0\u4e0a <code>-n<\/code> \u9078\u9805\uff1a<\/p>\n<pre><code>journalctl --unit=httpd.service -n 50<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u6700\u8fd1\u7684 50 \u689d\u65e5\u8a8c\u689d\u76ee\u3002<\/p>\n<h2 id=\"%e6%97%a5%e8%aa%8c%e9%81%8e%e6%bf%be%e8%88%87%e6%a0%bc%e5%bc%8f%e5%8c%96-ArLjWKzpFv\">\u65e5\u8a8c\u904e\u6ffe\u8207\u683c\u5f0f\u5316<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684\u67e5\u8a62\uff0c<code>journalctl<\/code> \u9084\u652f\u6301\u591a\u7a2e\u683c\u5f0f\u5316\u9078\u9805\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u5011\u60f3\u4ee5 JSON \u683c\u5f0f\u8f38\u51fa\u65e5\u8a8c\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>journalctl -o json<\/code><\/pre>\n<p>\u9019\u5c0d\u65bc\u9700\u8981\u9032\u4e00\u6b65\u8655\u7406\u65e5\u8a8c\u7684\u60c5\u6cc1\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h2 id=\"%e6%8c%81%e7%ba%8c%e7%9b%a3%e6%8e%a7%e6%97%a5%e8%aa%8c-ArLjWKzpFv\">\u6301\u7e8c\u76e3\u63a7\u65e5\u8a8c<\/h2>\n<p>\u5982\u679c\u9700\u8981\u5be6\u6642\u76e3\u63a7\u65e5\u8a8c\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>-f<\/code> \u9078\u9805\uff0c\u9019\u985e\u4f3c\u65bc <code>tail -f<\/code> \u7684\u529f\u80fd\uff1a<\/p>\n<pre><code>journalctl -f<\/code><\/pre>\n<p>\u9019\u5c07\u6301\u7e8c\u986f\u793a\u6700\u65b0\u7684\u65e5\u8a8c\u689d\u76ee\uff0c\u76f4\u5230\u7528\u6236\u624b\u52d5\u505c\u6b62\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ArLjWKzpFv\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4f7f\u7528 <code>journalctl<\/code>\uff0c\u7cfb\u7d71\u7ba1\u7406\u54e1\u53ef\u4ee5\u6709\u6548\u5730\u5206\u6790\u548c\u7ba1\u7406 CentOS 8 \u7684\u65e5\u8a8c\uff0c\u5f9e\u800c\u63d0\u9ad8\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u548c\u5b89\u5168\u6027\u3002\u7121\u8ad6\u662f\u904e\u6ffe\u7279\u5b9a\u670d\u52d9\u7684\u65e5\u8a8c\uff0c\u9084\u662f\u5be6\u6642\u76e3\u63a7\u7cfb\u7d71\u72c0\u614b\uff0c<code>journalctl<\/code> \u90fd\u63d0\u4f9b\u4e86\u9748\u6d3b\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u5404\u7a2e\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528 journalctl \u5728 CentOS 8 \u4e2d\u5206\u6790\u65e5\u8a8c\uff0c\u638c\u63e1\u7cfb\u7d71\u76e3\u63a7\u8207\u6545\u969c\u6392\u9664\u7684\u6280\u5de7\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43952","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43952","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=43952"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43952\/revisions"}],"predecessor-version":[{"id":43953,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43952\/revisions\/43953"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}