{"id":158341,"date":"2019-09-26T10:01:22","date_gmt":"2019-09-26T02:01:22","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=158341"},"modified":"2019-09-17T13:16:42","modified_gmt":"2019-09-17T05:16:42","slug":"how-linux-log","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/how-linux-log.html","title":{"rendered":"Linux \u7cfb\u7edf\u4e2d\u7684\u7ba1\u7406\u65e5\u5fd7"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nLinux \u7cfb\u7edf\u4e0a\u7684\u65e5\u5fd7\u6587\u4ef6\u5305\u542b\u4e86\u5f88\u591a\u4fe1\u606f\u2014\u2014\u6bd4\u4f60\u6709\u65f6\u95f4\u67e5\u770b\u7684\u8fd8\u8981\u591a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8bae\uff0c\u544a\u8bc9\u4f60\u5982\u4f55\u6b63\u786e\u7684\u4f7f\u7528\u5b83\u4eec\u2026\u2026\u800c\u4e0d\u662f\u6df9\u6ca1\u5728\u5176\u4e2d\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5728 Linux \u7cfb\u7edf\u4e0a\u7ba1\u7406\u65e5\u5fd7\u6587\u4ef6\u53ef\u80fd\u975e\u5e38\u5bb9\u6613\uff0c\u4e5f\u53ef\u80fd\u975e\u5e38\u75db\u82e6\u3002\u8fd9\u5b8c\u5168\u53d6\u51b3\u4e8e\u4f60\u6240\u8ba4\u4e3a\u7684\u65e5\u5fd7\u7ba1\u7406\u662f\u4ec0\u4e48\u3002<\/p>\n

\u5982\u679c\u4f60\u8ba4\u4e3a\u662f\u5982\u4f55\u786e\u4fdd\u65e5\u5fd7\u6587\u4ef6\u4e0d\u4f1a\u8017\u5c3d\u4f60\u7684 Linux \u670d\u52a1\u5668\u4e0a\u7684\u6240\u6709\u78c1\u76d8\u7a7a\u95f4\uff0c\u90a3\u4e48\u8fd9\u4e2a\u95ee\u9898\u901a\u5e38\u5f88\u7b80\u5355\u3002Linux \u7cfb\u7edf\u4e0a\u7684\u65e5\u5fd7\u6587\u4ef6\u4f1a\u81ea\u52a8\u7ffb\u8f6c\uff0c\u7cfb\u7edf\u5c06\u53ea\u7ef4\u62a4\u56fa\u5b9a\u6570\u91cf\u7684\u7ffb\u8f6c\u65e5\u5fd7\u3002\u5373\u4fbf\u5982\u6b64\uff0c\u4e00\u773c\u770b\u53bb\u4e00\u7ec4\u4e0a\u767e\u4e2a\u6587\u4ef6\u53ef\u80fd\u4f1a\u8ba9\u4eba\u4e0d\u77e5\u6240\u63aa\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u770b\u770b\u65e5\u5fd7\u8f6e\u6362\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff0c\u4ee5\u53ca\u4e00\u4e9b\u6700\u76f8\u5173\u7684\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n

\u81ea\u52a8\u65e5\u5fd7\u8f6e\u6362<\/strong><\/div>\n

\u65e5\u5fd7\u6587\u4ef6\u662f\u7ecf\u5e38\u8f6e\u8f6c\u7684\u3002\u5f53\u524d\u7684\u65e5\u5fd7\u4f1a\u83b7\u5f97\u7a0d\u5fae\u4e0d\u540c\u7684\u6587\u4ef6\u540d\uff0c\u5e76\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684\u65e5\u5fd7\u6587\u4ef6\u3002\u4ee5\u7cfb\u7edf\u65e5\u5fd7\u6587\u4ef6\u4e3a\u4f8b\u3002\u5bf9\u4e8e\u8bb8\u591a\u6b63\u5e38\u7684\u7cfb\u7edf messages \u6587\u4ef6\u6765\u8bf4\uff0c\u8fd9\u4e2a\u6587\u4ef6\u662f\u4e00\u4e2a\u5305\u7f57\u4e07\u8c61\u7684\u4e1c\u897f\u3002\u5982\u679c\u4f60 cd \u8f6c\u5230 \/var\/log \u5e76\u67e5\u770b\u4e00\u4e0b\uff0c\u4f60\u53ef\u80fd\u4f1a\u770b\u5230\u4e00\u7cfb\u5217\u7cfb\u7edf\u65e5\u5fd7\u6587\u4ef6\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n

$ ls -l syslog*\r\n-rw-r----- 1 syslog adm 28996 Jul 30 07:40 syslog\r\n-rw-r----- 1 syslog adm 71212 Jul 30 00:00 syslog.1\r\n-rw-r----- 1 syslog adm  5449 Jul 29 00:00 syslog.2.gz\r\n-rw-r----- 1 syslog adm  6152 Jul 28 00:00 syslog.3.gz\r\n-rw-r----- 1 syslog adm  7031 Jul 27 00:00 syslog.4.gz\r\n-rw-r----- 1 syslog adm  5602 Jul 26 00:00 syslog.5.gz\r\n-rw-r----- 1 syslog adm  5995 Jul 25 00:00 syslog.6.gz\r\n-rw-r----- 1 syslog adm 32924 Jul 24 00:00 syslog.7.gz<\/pre>\n

\u8f6e\u6362\u53d1\u751f\u5728\u6bcf\u5929\u5348\u591c\uff0c\u65e7\u7684\u65e5\u5fd7\u6587\u4ef6\u4f1a\u4fdd\u7559\u4e00\u5468\uff0c\u7136\u540e\u5220\u9664\u6700\u65e9\u7684\u7cfb\u7edf\u65e5\u5fd7\u6587\u4ef6\u3002syslog.7.gz \u6587\u4ef6\u5c06\u88ab\u4ece\u7cfb\u7edf\u4e2d\u5220\u9664\uff0csyslog.6.gz \u5c06\u88ab\u91cd\u547d\u540d\u4e3a syslog.7.gz\u3002\u65e5\u5fd7\u6587\u4ef6\u7684\u5176\u4f59\u90e8\u5206\u5c06\u4f9d\u6b21\u6539\u540d\uff0c\u76f4\u5230 syslog \u53d8\u6210 syslog.1 \u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 syslog \u6587\u4ef6\u3002\u6709\u4e9b\u7cfb\u7edf\u65e5\u5fd7\u6587\u4ef6\u4f1a\u6bd4\u5176\u4ed6\u6587\u4ef6\u5927\uff0c\u4f46\u662f\u4e00\u822c\u6765\u8bf4\uff0c\u6ca1\u6709\u4e00\u4e2a\u6587\u4ef6\u53ef\u80fd\u4f1a\u53d8\u5f97\u975e\u5e38\u5927\uff0c\u5e76\u4e14\u4f60\u6c38\u8fdc\u4e0d\u4f1a\u770b\u5230\u8d85\u8fc7\u516b\u4e2a\u7684\u6587\u4ef6\u3002\u8fd9\u7ed9\u4e86\u4f60\u4e00\u4e2a\u591a\u661f\u671f\u7684\u65f6\u95f4\u6765\u56de\u987e\u5b83\u4eec\u6536\u96c6\u7684\u4efb\u4f55\u6570\u636e\u3002<\/p>\n

\u67d0\u79cd\u7279\u5b9a\u65e5\u5fd7\u6587\u4ef6\u7ef4\u62a4\u7684\u6587\u4ef6\u6570\u91cf\u53d6\u51b3\u4e8e\u65e5\u5fd7\u6587\u4ef6\u672c\u8eab\u3002\u6709\u4e9b\u6587\u4ef6\u53ef\u80fd\u6709 13 \u4e2a\u3002\u8bf7\u6ce8\u610f syslog \u548c dpkg \u7684\u65e7\u6587\u4ef6\u662f\u5982\u4f55\u538b\u7f29\u4ee5\u8282\u7701\u7a7a\u95f4\u7684\u3002\u8fd9\u91cc\u7684\u8003\u8651\u662f\u4f60\u5bf9\u6700\u8fd1\u7684\u65e5\u5fd7\u6700\u611f\u5174\u8da3\uff0c\u800c\u66f4\u65e7\u7684\u65e5\u5fd7\u53ef\u4ee5\u6839\u636e\u9700\u8981\u7528 gunzip \u89e3\u538b\u3002<\/p>\n

\u65e5\u5fd7\u6587\u4ef6\u53ef\u4ee5\u6839\u636e\u65f6\u95f4\u548c\u5927\u5c0f\u8fdb\u884c\u8f6e\u6362\u3002\u68c0\u67e5\u65e5\u5fd7\u6587\u4ef6\u65f6\u8bf7\u8bb0\u4f4f\u8fd9\u4e00\u70b9\u3002<\/p>\n

\u5c3d\u7ba1\u9ed8\u8ba4\u503c\u9002\u7528\u4e8e\u5927\u591a\u6570 Linux \u7cfb\u7edf\u7ba1\u7406\u5458\uff0c\u4f46\u5982\u679c\u4f60\u613f\u610f\uff0c\u53ef\u4ee5\u5bf9\u65e5\u5fd7\u6587\u4ef6\u8f6e\u6362\u8fdb\u884c\u4e0d\u540c\u7684\u914d\u7f6e\u3002\u67e5\u770b\u8fd9\u4e9b\u6587\u4ef6\uff0c\u5982 \/etc\/rsyslog.conf \u548c \/etc\/logrotate.conf\u3002<\/p>\n

\u4f7f\u7528\u65e5\u5fd7\u6587\u4ef6<\/strong><\/div>\n

\u5bf9\u65e5\u5fd7\u6587\u4ef6\u7684\u7ba1\u7406\u4e5f\u5305\u62ec\u65f6\u4e0d\u65f6\u7684\u4f7f\u7528\u5b83\u4eec\u3002\u4f7f\u7528\u65e5\u5fd7\u6587\u4ef6\u7684\u7b2c\u4e00\u6b65\u53ef\u80fd\u5305\u62ec\uff1a\u4e60\u60ef\u6bcf\u4e2a\u65e5\u5fd7\u6587\u4ef6\u53ef\u4ee5\u544a\u8bc9\u4f60\u6709\u5173\u7cfb\u7edf\u5982\u4f55\u5de5\u4f5c\u4ee5\u53ca\u7cfb\u7edf\u53ef\u80fd\u4f1a\u9047\u5230\u54ea\u4e9b\u95ee\u9898\u3002\u4ece\u5934\u5230\u5c3e\u8bfb\u53d6\u65e5\u5fd7\u6587\u4ef6\u51e0\u4e4e\u4e0d\u662f\u4e00\u4e2a\u597d\u7684\u9009\u62e9\uff0c\u4f46\u662f\u5f53\u4f60\u60f3\u4e86\u89e3\u4f60\u7684\u7cfb\u7edf\u8fd0\u884c\u7684\u60c5\u51b5\u6216\u8005\u9700\u8981\u8ddf\u8e2a\u4e00\u4e2a\u95ee\u9898\u65f6\uff0c\u77e5\u9053\u5982\u4f55\u4ece\u65e5\u5fd7\u6587\u4ef6\u4e2d\u83b7\u53d6\u4fe1\u606f\u4f1a\u662f\u6709\u5f88\u5927\u7684\u597d\u5904\u3002\u8fd9\u4e5f\u8868\u660e\u4f60\u5bf9\u6bcf\u4e2a\u6587\u4ef6\u4e2d\u5b58\u50a8\u7684\u4fe1\u606f\u6709\u4e00\u4e2a\u5927\u81f4\u7684\u4e86\u89e3\u4e86\u3002\u4f8b\u5982:<\/p>\n

$ who wtmp | tail -10           \u663e\u793a\u6700\u8fd1\u7684\u767b\u5f55\u4fe1\u606f\r\n$ who wtmp | grep shark         \u663e\u793a\u7279\u5b9a\u7528\u6237\u7684\u6700\u8fd1\u767b\u5f55\u4fe1\u606f\r\n$ grep \"sudo:\" auth.log         \u67e5\u770b\u8c01\u5728\u4f7f\u7528 sudo\r\n$ tail dmesg                    \u67e5\u770b\uff08\u6700\u8fd1\u7684\uff09\u5185\u6838\u65e5\u5fd7\r\n$ tail dpkg.log                 \u67e5\u770b\u6700\u8fd1\u5b89\u88c5\u548c\u66f4\u65b0\u7684\u8f6f\u4ef6\u5305\r\n$ more ufw.log                  \u67e5\u770b\u9632\u706b\u5899\u6d3b\u52a8\uff08\u5047\u5982\u4f60\u4f7f\u7528 ufw\uff09<\/pre>\n

\u4f60\u8fd0\u884c\u7684\u4e00\u4e9b\u547d\u4ee4\u4e5f\u4f1a\u4ece\u65e5\u5fd7\u6587\u4ef6\u4e2d\u63d0\u53d6\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u67e5\u770b\u7cfb\u7edf\u91cd\u65b0\u542f\u52a8\u7684\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4:<\/p>\n

$ last reboot\r\nreboot   system boot  5.0.0-20-generic Tue Jul 16 13:19   still running\r\nreboot   system boot  5.0.0-15-generic Sat May 18 17:26 - 15:19 (21+21:52)\r\nreboot   system boot  5.0.0-13-generic Mon Apr 29 10:55 - 15:34 (18+04:39)<\/pre>\n
\u4f7f\u7528\u66f4\u9ad8\u7ea7\u7684\u65e5\u5fd7\u7ba1\u7406\u5668<\/strong><\/div>\n

\u867d\u7136\u4f60\u53ef\u4ee5\u7f16\u5199\u811a\u672c\u6765\u66f4\u5bb9\u6613\u5730\u5728\u65e5\u5fd7\u6587\u4ef6\u4e2d\u627e\u5230\u611f\u5174\u8da3\u7684\u4fe1\u606f\uff0c\u4f46\u662f\u4f60\u4e5f\u5e94\u8be5\u77e5\u9053\u6709\u4e00\u4e9b\u975e\u5e38\u590d\u6742\u7684\u5de5\u5177\u53ef\u7528\u4e8e\u65e5\u5fd7\u6587\u4ef6\u5206\u6790\u3002\u4e00\u4e9b\u53ef\u4ee5\u628a\u6765\u81ea\u591a\u4e2a\u6765\u6e90\u7684\u4fe1\u606f\u8054\u7cfb\u8d77\u6765\uff0c\u4ee5\u4fbf\u66f4\u5168\u9762\u5730\u4e86\u89e3\u4f60\u7684\u7f51\u7edc\u4e0a\u53d1\u751f\u4e86\u4ec0\u4e48\u3002\u5b83\u4eec\u4e5f\u53ef\u4ee5\u63d0\u4f9b\u5b9e\u65f6\u76d1\u63a7\u3002\u8fd9\u4e9b\u5de5\u5177\uff0c\u5982 Solarwinds Log & Event Manager \u548c PRTG \u7f51\u7edc\u76d1\u89c6\u5668\uff08\u5305\u62ec\u65e5\u5fd7\u76d1\u89c6\uff09\u6d6e\u73b0\u5728\u8111\u6d77\u4e2d\u3002<\/p>\n

\u8fd8\u6709\u4e00\u4e9b\u514d\u8d39\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u5206\u6790\u65e5\u5fd7\u6587\u4ef6\u3002\u5176\u4e2d\u5305\u62ec:<\/p>\n

Logwatch \u2014 \u7528\u4e8e\u626b\u63cf\u7cfb\u7edf\u65e5\u5fd7\u4e2d\u611f\u5174\u8da3\u7684\u65e5\u5fd7\u884c\u7684\u7a0b\u5e8f
\nLogcheck \u2014 \u7cfb\u7edf\u65e5\u5fd7\u5206\u6790\u5668\u548c\u62a5\u544a\u5668<\/p>\n


\n

via: https:\/\/www.networkworld.com\/article\/3428361\/how-to-manage-logs-in-linux.html<\/a><\/p>\n

\u4f5c\u8005\uff1aSandra Henry-Stocker \u8bd1\u8005\uff1aheguangzhi \u6821\u5bf9\uff1awxy<\/p>\n

\u672c\u6587\u7531 LCTT<\/a> \u539f\u521b\u7ffb\u8bd1\uff0cLinux\u4e2d\u56fd<\/a> \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728 Linux \u7cfb\u7edf\u4e0a\u7ba1\u7406\u65e5\u5fd7\u6587\u4ef6\u53ef\u80fd\u975e\u5e38\u5bb9\u6613\uff0c\u4e5f\u53ef\u80fd\u975e\u5e38\u75db\u82e6\u3002\u8fd9\u5b8c\u5168\u53d6\u51b3\u4e8e\u4f60\u6240\u8ba4\u4e3a\u7684\u65e5\u5fd7\u7ba1\u7406\u662f\u4ec0\u4e48\u3002 \u5982\u679c\u4f60 […]<\/p>\n","protected":false},"author":310,"featured_media":158343,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-158341","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/158341","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\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=158341"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/158341\/revisions"}],"predecessor-version":[{"id":158369,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/158341\/revisions\/158369"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/158343"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=158341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=158341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=158341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}