2.\u5220\u9664\u8d85\u8fc7 X \u5929\u672a\u4fee\u6539\u7684\u6587\u4ef6<\/strong><\/span><\/div>\n\u524d\u6587\u63d0\u5230\uff0c tmpwatch \u9ed8\u8ba4\u6839\u636e\u8bbf\u95ee\u65f6\u95f4\u6765\u5220\u9664\u6587\u4ef6\u7684\uff0c\u73b0\u5728\u6211\u4eec\u4f7f\u7528 -m \u9009\u9879\u6765\u6839\u636e\u6587\u4ef6\u7684\u4fee\u6539\u65f6\u95f4(modification time)\u6765\u5220\u9664\u6587\u4ef6\u3002<\/p>\n
\u4f8b\uff1a\u5220\u9664 \/var\/log\/ \u6587\u4ef6\u5939\u4e2d\u8d85\u8fc7 10 \u5929\u672a\u4fee\u6539\u7684\u6587\u4ef6<\/p>\n
tmpwatch -m 10d \/var\/log\/ <\/pre>\n\u4e0a\u9762\u4e24\u4e2a\u547d\u4ee4\u4e2d\u7684 d \u662f\u65f6\u95f4\u53c2\u6570\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n
d - \u5929\u6570
\nh - \u5c0f\u65f6
\nm - \u5206\u949f
\ns - \u79d2\u6570
\n\u9ed8\u8ba4\u65f6\u95f4\u53c2\u6570\u662f\u5c0f\u65f6 \u3002\u5047\u5982\u60f3\u5220\u9664\u8fc7\u53bb 10 \u4e2a\u5c0f\u65f6\u672a\u4fee\u6539\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u5199\u6210\u4e0b\u9762\u8fd9\u79cd\u5f62\u5f0f\uff1a<\/p>\n
tmpwatch -m 10 \/var\/log\/<\/pre>\n3. \u5220\u9664\u7b26\u53f7\u94fe\u63a5<\/strong><\/span><\/div>\n\u53ef\u4ee5\u4f7f\u7528 -s \u9009\u9879\u5220\u9664\u7b26\u53f7\u94fe\u63a5\uff1a<\/p>\n
tmpwatch -s 10 \/var\/log\/<\/pre>\n4. \u5220\u9664\u6240\u6709\u6587\u4ef6(\u5305\u62ec\u5e38\u89c4\u6587\u4ef6\uff0c\u7b26\u53f7\u94fe\u63a5\u548c\u76ee\u5f55)<\/strong><\/span><\/div>\ntmpwatch \u4e0d\u4ec5\u4ec5\u53ef\u4ee5\u5220\u666e\u901a\u6587\u4ef6\uff0c\u8fd8\u53ef\u4ee5\u5220\u9664\u4e00\u4e9b\u7279\u6b8a\u6587\u4ef6\uff0c\u6bd4\u5982\u7b26\u53f7\u94fe\u63a5\u3001\u76ee\u5f55\u3001\u7ba1\u9053\u6587\u4ef6\u7b49\u7b49\u3002\u8fd9\u4e2a\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u4f7f\u7528 -a \u9009\u9879\uff1a<\/p>\n
tmpwatch -s 10 \/var\/log\/<\/pre>\n5. \u5220\u9664\u65f6\u6392\u9664\u76ee\u5f55<\/strong><\/span><\/div>\n\u5982\u679c\u4e0d\u60f3\u5220\u9664\u67d0\u4e2a\u76ee\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528 --nodirs \u9009\u9879\uff0c\u5728\u5220\u9664\u65f6\u6392\u9664\u5bf9\u8be5\u76ee\u5f55\u7684\u5220\u9664\uff1a<\/p>\n
tmpwatch -am 10 --nodirs \/var\/log\/ <\/pre>\n6. \u6d4b\u8bd5\u5220\u9664(\u4e0d\u5b9e\u9645\u5220\u9664\u4efb\u4f55\u5185\u5bb9)<\/strong><\/span><\/div>\n\u8fd9\u91cc\u8981\u518d\u6b21\u5f3a\u8c03\uff0c\u5728\u5bf9\u91cd\u8981\u76ee\u5f55\u8fdb\u884c\u6587\u4ef6\u5220\u9664\u65f6\uff0c\u4e0d\u8981\u6025\u7740\u4f7f\u7528 tmpwatch \u547d\u4ee4!\u4e0d\u59a8\u5148\u770b\u770b\u547d\u4ee4\u8fd0\u884c\u4e4b\u540e\u5220\u9664\u7684\u6587\u4ef6\u6709\u54ea\u4e9b\uff0c\u4e0d\u7136\u5220\u9519\u4e86\u8111\u58f3\u53c8\u75bc\u4e86\u3002\u3002(\u517b\u6210\u4e00\u79cd\u597d\u4e60\u60ef!)<\/p>\n
\u53ef\u4ee5\u4f7f\u7528 -t \u8fdb\u5165\u6d4b\u8bd5\u6a21\u5f0f\uff1a<\/p>\n
tmpwatch -t 30 \/var\/log\/<\/pre>\nCentOS 7 \u4e0b\u8f93\u51fa\uff1a<\/p>\n
removing file \/var\/log\/wtmp \r\nremoving directory \/var\/log\/ppp if empty \r\nremoving directory \/var\/log\/tuned if empty \r\nremoving directory \/var\/log\/anaconda if empty \r\nremoving file \/var\/log\/dmesg.old \r\nremoving file \/var\/log\/boot.log \r\nremoving file \/var\/log\/dnf.librepo.log <\/pre>\n\u57fa\u4e8e Debian \u7684\u7cfb\u7edf\u4e0b\u8f93\u51fa\uff1a<\/p>\n
$ tmpreaper -t 30 \/var\/log\/ \r\n(PID 1803) Pretending to clean up directory `\/var\/log\/'. \r\n(PID 1804) Pretending to clean up directory `apache2'. \r\nPretending to remove file `apache2\/error.log'. \r\nPretending to remove file `apache2\/access.log'. \r\nPretending to remove file `apache2\/other_vhosts_access.log'. \r\n(PID 1804) Back from recursing down `apache2'. \r\n(PID 1804) Pretending to clean up directory `dbconfig-common'. \r\nPretending to remove file `dbconfig-common\/dbc.log'. \r\n(PID 1804) Back from recursing down `dbconfig-common'. \r\n(PID 1804) Pretending to clean up directory `dist-upgrade'. \r\n(PID 1804) Back from recursing down `dist-upgrade'. \r\n(PID 1804) Pretending to clean up directory `lxd'. \r\n(PID 1804) Back from recursing down `lxd'. \r\nPretending to remove file `\/var\/log\/\/cloud-init.log'. \r\n(PID 1804) Pretending to clean up directory `landscape'. \r\nPretending to remove file `landscape\/sysinfo.log'. \r\n(PID 1804) Back from recursing down `landscape'. \r\n[...] <\/pre>\n\u4e0a\u9762\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u5176\u5b9e\u5e76\u6ca1\u6709\u771f\u6b63\u5220\u9664\u6587\u4ef6\uff0c\u53ea\u662f\u8fdb\u884c\u6a21\u62df\u5220\u9664\uff0c\u544a\u77e5\u4f60\u54ea\u4e9b\u6587\u4ef6\u4f1a\u88ab\u5220\u9664\u3002<\/p>\n
\u5728\u786e\u4fdd\u8981\u5220\u9664\u7684\u6587\u4ef6\u90fd\u662f\u6b63\u786e\u7684\u65f6\u5019\uff0c\u65b9\u53ef\u53bb\u6389 -t \u9009\u9879\u518d\u6267\u884c tmpwatch \u8fdb\u884c\u771f\u6b63\u5220\u9664\u3002<\/p>\n
7. \u5f3a\u5236\u5220\u9664<\/strong><\/span><\/div>\ntmpwatch \u9ed8\u8ba4\u4e0d\u4f1a\u5220\u9664\u5f53\u524d\u7528\u6237\u6ca1\u6709\u5199\u8bbf\u95ee\u6743\u7684\u6587\u4ef6\u3002\u4f46\u662f\u5982\u679c\u4f60\u5fc5\u987b\u8981\u5220\u9664\u90a3\u4e9b\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528-f \u9009\u9879\u8fdb\u884c\u5f3a\u5236\u5220\u9664\uff1a<\/p>\n
tmpwatch -f 10h \/var\/log\/<\/pre>\n8. \u5220\u9664\u65f6\u8df3\u8fc7\u67d0\u4e9b\u6587\u4ef6<\/strong><\/span><\/div>\n\u82e5\u60f3\u5728\u5220\u9664\u65f6\u4fdd\u7559\u6307\u5b9a\u7684\u6587\u4ef6\uff0c\u4e5f\u5c31\u662f\u8bf4\u5217\u5165\u767d\u540d\u5355\uff0c\u53ef\u4ee5\u4f7f\u7528 --protect \u9009\u9879\u3002\u5047\u8bbe\u6211\u4eec\u8981\u4fdd\u7559\u6240\u6709 txt \u7c7b\u578b\u7684\u6587\u4ef6\uff1a<\/p>\n
tmpreaper --protect '*.txt' -t 10h \/var\/log\/ <\/pre>\n\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n
(PID 2623) Pretending to clean up directory `\/var\/log\/'. \r\n(PID 2624) Pretending to clean up directory `apache2'. \r\nPretending to remove file `apache2\/error.log'. \r\nPretending to remove file `apache2\/access.log'. \r\nPretending to remove file `apache2\/other_vhosts_access.log'. \r\n(PID 2624) Back from recursing down `apache2'. \r\n(PID 2624) Pretending to clean up directory `dbconfig-common'. \r\nPretending to remove file `dbconfig-common\/dbc.log'. \r\n(PID 2624) Back from recursing down `dbconfig-common'. \r\n(PID 2624) Pretending to clean up directory `dist-upgrade'. \r\n(PID 2624) Back from recursing down `dist-upgrade'. \r\nPretending to remove empty directory `dist-upgrade'. \r\nEntry matching `--protect' pattern skipped. `ostechnix.txt' \r\n(PID 2624) Pretending to clean up directory `lxd'. <\/pre>\n\u8bbe\u7f6e cron job \u5b9a\u671f\u81ea\u52a8\u5220\u9664\u6587\u4ef6<\/strong><\/div>\n(\u5077\u5077\u5730\u544a\u8bc9\u4f60\uff0ctmpwatch\/tmpreaper \u4e0e cron job \u4e00\u8d77\u98df\u7528\u66f4\u4f73\u54e6\u3002)<\/p>\n
\u8fdb\u5165 cron job \u4efb\u52a1\u7f16\u8f91\u7a97\u53e3\uff1a<\/p>\n
# crontab -e <\/pre>\n\u6dfb\u52a0\u4e00\u4e2a\u5468\u671f\u4efb\u52a1\uff1a<\/p>\n
0 1 * * * \/usr\/sbin\/tmpwatch 30d \/var\/log\/ <\/pre>\n\u4e0a\u9762\u7684\u4ee3\u7801\u8bbe\u7f6e\u4e86 tmpwatch \u6bcf\u5929\u51cc\u6668 1 \u70b9\u8fd0\u884c\uff0c\u5e76\u5220\u9664 30 \u5929\u4e4b\u524d\u7684\u6587\u4ef6\u3002<\/p>\n
\u4e0d\u4e86\u89e3 corn job \u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u4e0a\u7f51\u641c\u4e0b\u5b83\u7684\u521d\u5b66\u8005\u6307\u5357\u54c8\u3002<\/p>\n
\u5b89\u88c5 tmpreaper \u65f6\uff0c\u5b83\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u65e5\u5e38 cron job(\/etc\/cron.daily\/Tmpreaper)\u3002\u5b83\u4ece \/etc\/timereaper.conf \u6587\u4ef6\u4e2d\u8bfb\u53d6\u914d\u7f6e\u5e76\u6267\u884c\u3002\u9ed8\u8ba4\u8bbe\u7f6e\u7684\u662f\u5220\u9664 7 \u5929\u4ee5\u524d\u7684\u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 TMPREAPER.conf \u6587\u4ef6\u4e2d \u201cTMPREAPER_TIME=7d\u201d \u6765\u66f4\u6539\u8fd9\u9879\u8bbe\u7f6e\u3002<\/p>\n
\u5199\u5728\u6700\u540e<\/strong><\/div>\n\u6700\u540e\u5728\u63d0\u9192\u4e00\u4e0b\uff0c\u5728\u5220\u9664\u6587\u4ef6\u7684\u65f6\u5019\u4e00\u5b9a\u8981\u4ed4\u7ec6\u68c0\u67e5\u597d\u8def\u5f84\uff0c\u4ee5\u514d\u6570\u636e\u4e22\u5931\u3002<\/p>\n
tmpwatch \u548c tmpreaper \u624b\u518c\u9875\uff1a<\/p>\n
$ man tmpwatch \r\n$ man tmpreaper<\/pre>\n","protected":false},"excerpt":{"rendered":"\u4e0b\u9762\u8981\u4ecb\u7ecd\u7684\u662f\u4eca\u5929\u7684\u4e3b\u89d2\u2014\u2014 tmpwatch \uff0c\u5b83\u80fd\u5e2e\u52a9\u6211\u4eec\u9012\u5f52\u5220\u9664\u5728\u7ed9\u5b9a\u65f6\u95f4\u5185\u6ca1\u6709\u8bbf\u95ee\u7684\u6587\u4ef6\u548c\u7a7a\u76ee\u5f55\u3002 \u5f53 […]<\/p>\n","protected":false},"author":1920,"featured_media":173831,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-174410","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\/174410","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\/1920"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=174410"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/174410\/revisions"}],"predecessor-version":[{"id":174441,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/174410\/revisions\/174441"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/173831"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=174410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=174410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=174410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}