{"id":250825,"date":"2022-08-27T09:00:19","date_gmt":"2022-08-27T01:00:19","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=250825"},"modified":"2022-08-26T11:23:43","modified_gmt":"2022-08-26T03:23:43","slug":"linux-jiankong","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-jiankong.html","title":{"rendered":"\u5982\u4f55\u5728 Linux \u4e2d\u5b9e\u65f6\u76d1\u63a7\u65e5\u5fd7\u6587\u4ef6\uff08\u684c\u9762\u548c\u670d\u52a1\u5668\uff09"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u6559\u7a0b\u4ecb\u7ecd\u4e86\u5982\u4f55\u5b9e\u65f6\u76d1\u63a7 Linux \u65e5\u5fd7\u6587\u4ef6\uff08\u684c\u9762\u3001\u670d\u52a1\u5668\u6216\u5e94\u7528\uff09\u4ee5\u8fdb\u884c\u8bca\u65ad\u548c\u6545\u969c\u6392\u9664\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5f53\u4f60\u5728 Linux \u684c\u9762\u3001\u670d\u52a1\u5668\u6216\u4efb\u4f55\u5e94\u7528\u4e2d\u9047\u5230\u95ee\u9898\u65f6\uff0c\u4f60\u9996\u5148\u4f1a\u67e5\u770b\u5355\u72ec\u7684\u65e5\u5fd7\u6587\u4ef6\u3002\u65e5\u5fd7\u6587\u4ef6\u901a\u5e38\u662f\u6587\u672c\u6d41\u548c\u6765\u81ea\u5e94\u7528\u7684\u5e26\u6709\u65f6\u95f4\u6233\u7684\u6d88\u606f\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u7f29\u5c0f\u7279\u5b9a\u95ee\u9898\u7684\u8303\u56f4\uff0c\u5e76\u4f7f\u4f60\u80fd\u591f\u627e\u5230\u95ee\u9898\u7684\u539f\u56e0\u3002\u5b83\u8fd8\u53ef\u4ee5\u5e2e\u52a9\u4ece\u7f51\u7edc\u83b7\u5f97\u5e2e\u52a9\u3002<\/p>\n

\u4e00\u822c\u6765\u8bf4\uff0c\u6240\u6709\u7684\u65e5\u5fd7\u6587\u4ef6\u90fd\u4f4d\u4e8e \/var\/log\u200b\u3002\u6b64\u76ee\u5f55\u5305\u542b\u7279\u5b9a\u5e94\u7528\u548c\u670d\u52a1\u7684\u6269\u5c55\u540d\u4e3a .log \u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u5b83\u8fd8\u5305\u542b\u4e86\u5176\u4ed6\u542b\u6709\u65e5\u5fd7\u7684\u72ec\u7acb\u76ee\u5f55\u3002<\/p>\n

\"\"
\n\u6240\u4ee5\uff0c\u5982\u679c\u4f60\u60f3\u76d1\u63a7\u4e00\u5806\u65e5\u5fd7\u6587\u4ef6\u6216\u7279\u5b9a\u7684\u4e00\u4e2a\uff0c\u8fd9\u91cc\u6709\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u505a\u5230\u3002<\/p>\n

Linux \u5b9e\u65f6\u76d1\u63a7\u65e5\u5fd7\u6587\u4ef6<\/strong><\/div>\n

\u4f7f\u7528 tail \u547d\u4ee4
\ntail \u547d\u4ee4\u662f\u5b9e\u65f6\u8ddf\u8e2a\u65e5\u5fd7\u6587\u4ef6\u7684\u6700\u57fa\u672c\u65b9\u5f0f\u3002\u7279\u522b\u662f\u5982\u679c\u4f60\u5728\u53ea\u6709\u7ec8\u7aef\u800c\u6ca1\u6709 GUI \u7684\u670d\u52a1\u5668\u4e2d\u3002\u8fd9\u5f88\u6709\u5e2e\u52a9\u3002<\/p>\n

\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n

tail \/path\/to\/log\/file<\/pre>\n

\"\"
\nMonitoring multiple log files via tail<\/p>\n

\u53ef\u4ee5\u4f7f\u7528\u5f00\u5173 -f \u8ddf\u8e2a\u5b9e\u65f6\u66f4\u65b0\u7684\u65e5\u5fd7\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8981\u5173\u6ce8 syslog\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n

tail -f \/var\/log\/syslog<\/pre>\n

\u4f60\u53ef\u4ee5\u4f7f\u7528\u5355\u4e2a\u547d\u4ee4\u76d1\u63a7\u591a\u4e2a\u65e5\u5fd7\u6587\u4ef6\uff1a<\/p>\n

tail -f \/var\/log\/syslog \/var\/log\/dmesg<\/pre>\n

\u5982\u679c\u8981\u76d1\u89c6 HTTP \u6216 sftp \u6216\u4efb\u4f55\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u5728\u6b64\u547d\u4ee4\u4e2d\u4f7f\u7528\u5b83\u4eec\u5404\u81ea\u7684\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n

\u8bf7\u8bb0\u4f4f\uff0c\u4e0a\u8ff0\u547d\u4ee4\u9700\u8981\u7ba1\u7406\u5458\u6743\u9650\u3002<\/p>\n

\u4f7f\u7528 lnav\uff08\u65e5\u5fd7\u6587\u4ef6\u6d4f\u89c8\u5668\uff09<\/p>\n

\"\"
\nlnav \u662f\u4e00\u4e2a\u51fa\u8272\u7684\u7a0b\u5e8f\uff0c\u4f60\u53ef\u4ee5\u7528\u5b83\u6765\u7528\u5f69\u8272\u7f16\u7801\u7684\u4fe1\u606f\u4ee5\u66f4\u6709\u6761\u7406\u7684\u65b9\u5f0f\u76d1\u63a7\u65e5\u5fd7\u6587\u4ef6\u3002\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u8fd9\u4e2a\u5de5\u5177\u4e0d\u662f\u9ed8\u8ba4\u5b89\u88c5\u7684\u3002\u4f60\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u6765\u5b89\u88c5\u5b83\uff1a<\/p>\n

Ubuntu\uff1a<\/p>\n

sudo apt install lnav<\/pre>\n

Fedora\uff1a<\/p>\n

sudo dnf install lnav<\/pre>\n

lnav \u7684\u597d\u5904\u5728\u4e8e\uff0c\u5982\u679c\u4f60\u4e0d\u60f3\u5b89\u88c5\u5b83\uff0c\u4f60\u53ef\u4ee5\u4e0b\u8f7d\u5176\u9884\u7f16\u8bd1\u7684\u53ef\u6267\u884c\u6587\u4ef6\u5e76\u5728\u4efb\u4f55\u5730\u65b9\u8fd0\u884c\u5b83\uff0c\u751a\u81f3\u53ef\u4ee5\u4ece U \u76d8\u4e0a\u8fd0\u884c\u3002\u65e0\u9700\u8bbe\u7f6e\uff0c\u5e76\u52a0\u8f7d\u4e86\u529f\u80fd\u3002\u4f7f\u7528 lnav\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7 SQL \u67e5\u8be2\u65e5\u5fd7\u6587\u4ef6\uff0c\u4ee5\u53ca\u5176\u4ed6\u5f88\u9177\u7684\u529f\u80fd\uff0c\u4f60\u53ef\u4ee5\u5728\u5176\u5b98\u65b9\u7f51\u7ad9\u4e0a\u5b66\u4e60\u3002<\/p>\n

\u5b89\u88c5\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u5177\u6709\u7ba1\u7406\u5458\u6743\u9650\u7684\u7ec8\u7aef\u4e0a\u8fd0\u884c lnav\u200b\uff0c\u5b83\u4f1a\u9ed8\u8ba4\u663e\u793a \/var\/log \u4e2d\u7684\u6240\u6709\u65e5\u5fd7\u5e76\u5f00\u59cb\u5b9e\u65f6\u76d1\u63a7\u3002<\/p>\n

\u5173\u4e8e systemd \u7684 journalctl \u7684\u4e00\u4e2a\u8bf4\u660e
\n\u5f53\u4eca\u6240\u6709\u73b0\u4ee3 Linux \u53d1\u884c\u7248\u90fd\u4e3b\u8981\u4f7f\u7528 systemd\u3002 systemd \u63d0\u4f9b\u4e86\u8fd0\u884c Linux \u64cd\u4f5c\u7cfb\u7edf\u7684\u57fa\u672c\u6846\u67b6\u548c\u7ec4\u4ef6\u3002 systemd \u901a\u8fc7 journalctl \u63d0\u4f9b\u65e5\u5fd7\u670d\u52a1\uff0c\u8fd9\u6709\u52a9\u4e8e\u7ba1\u7406\u6765\u81ea\u6240\u6709 systemd \u670d\u52a1\u7684\u65e5\u5fd7\u3002\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b9e\u65f6\u76d1\u63a7\u5404\u4e2a systemd \u670d\u52a1\u548c\u65e5\u5fd7\u3002<\/p>\n

journalctl -f<\/pre>\n

\u4ee5\u4e0b\u662f\u4e00\u4e9b\u7279\u5b9a\u7684 journalctl\u200b \u547d\u4ee4\uff0c\u53ef\u7528\u4e8e\u591a\u79cd\u60c5\u51b5\u3002\u4f60\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u4e0e\u4e0a\u9762\u7684 -f \u9009\u9879\u7ed3\u5408\u4f7f\u7528\u4ee5\u5f00\u59cb\u5b9e\u65f6\u76d1\u63a7\u3002<\/p>\n

\u5bf9\u4e8e\u7d27\u6025\u7cfb\u7edf\u6d88\u606f\uff0c\u8bf7\u4f7f\u7528\uff1a<\/p>\n

journalctl -p 0<\/pre>\n

\u663e\u793a\u5e26\u6709\u89e3\u91ca\u7684\u9519\u8bef\uff1a<\/p>\n

journalctl -xb -p 3<\/pre>\n

\u4f7f\u7528\u65f6\u95f4\u63a7\u5236\u8fc7\u6ee4\uff1a<\/p>\n

    journalctl --since \"2022-12-04 06:00:00\"\r\n    journalctl --since \"2022-12-03\" --until \"2022-12-05 03:00:00\"\r\n    journalctl --since yesterday\r\n    journalctl --since 09:00 --until \"1 hour ago\"\r\n<\/pre>\n

\u5982\u679c\u4f60\u60f3\u4e86\u89e3\u66f4\u591a\u5173\u4e8e journalctl \u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u6211\u5df2\u7ecf\u5728\u8fd9\u5199\u4e86\u4efd \u6307\u5357\u3002<\/p>\n

\u7ed3\u675f\u8bed<\/strong><\/div>\n

\u6211\u5e0c\u671b\u8fd9\u4e9b\u547d\u4ee4\u548c\u6280\u5de7\u53ef\u4ee5\u5e2e\u52a9\u4f60\u627e\u5230\u684c\u9762\u6216\u670d\u52a1\u5668\u4e2d\u95ee\u9898\/\u9519\u8bef\u7684\u6839\u672c\u539f\u56e0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5f53\u4f60\u5728 Linux \u684c\u9762\u3001\u670d\u52a1\u5668\u6216\u4efb\u4f55\u5e94\u7528\u4e2d\u9047\u5230\u95ee\u9898\u65f6\uff0c\u4f60\u9996\u5148\u4f1a\u67e5\u770b\u5355\u72ec\u7684\u65e5\u5fd7\u6587\u4ef6\u3002\u65e5\u5fd7\u6587\u4ef6\u901a\u5e38\u662f\u6587\u672c\u6d41\u548c\u6765\u81ea […]<\/p>\n","protected":false},"author":1469,"featured_media":250831,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[21],"tags":[],"class_list":["post-250825","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/250825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=250825"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/250825\/revisions"}],"predecessor-version":[{"id":251197,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/250825\/revisions\/251197"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/250831"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=250825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=250825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=250825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}