{"id":161131,"date":"2019-10-31T09:00:45","date_gmt":"2019-10-31T01:00:45","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=161131"},"modified":"2019-10-17T10:55:14","modified_gmt":"2019-10-17T02:55:14","slug":"nginx-logrotate","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/nginx-logrotate.html","title":{"rendered":"nginx\u65e5\u5fd7\u5207\u5272\u8be6\u89e3"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u65e5\u5fd7\u7684\u5173\u952e\u6027\u5c31\u4e0d\u7528\u591a\u8bf4\u4e86\uff0c\u5bf9\u4e8e\u7f51\u7ad9\u7684\u65e5\u5fd7\u6765\u8bf4\uff0c\u5982\u679c\u7f51\u7ad9\u8bbf\u95ee\u91cf\u8f83\u5927\uff0c\u6bcf\u5929\u4ea7\u751f\u7684\u65e5\u5fd7\u4e5f\u662f\u975e\u5e38\u5e9e\u5927\u7684\uff0cnginx\u9ed8\u8ba4\u90fd\u662f\u5c06\u65e5\u5fd7\u5199\u5165\u5230\u6307\u5b9a\u7684\u65e5\u5fd7\u6587\u4ef6\u4e2d\uff0c\u5982\u679c\u65e5\u5fd7\u6587\u4ef6\u53d8\u5f97\u975e\u5e38\u5927\uff0c\u90a3\u4e48\u81ea\u7136\u7684\u5199\u5165\u65e5\u5fd7\u5c31\u8f83\u6162\uff0c\u5982\u679c\u6211\u4eec\u9700\u8981\u5206\u6790\u65e5\u5fd7\uff0c\u5bf9\u4e8e\u51e0\u767e\u5146\u6216\u8005\u51e0G\u7684\u6587\u4ef6\uff0c\u5206\u6790\u8d77\u6765\u4e5f\u5f88\u4e0d\u65b9\u4fbf\uff0c\u8fd9\u91cc\u6211\u91c7\u7528\u7684\u662f\u7cfb\u7edf\u81ea\u5e26\u65e5\u5fd7\u8f6e\u8be2logrotate \u5bf9nginx \u65e5\u5fd7\u8fdb\u884c\u5272\u5207\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
logrotate\u914d\u7f6e<\/strong><\/span><\/div>\n

logrotate \u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u5728\/etc\/logrotate.conf \u4e3b\u914d\u7f6e\u6587\u4ef6\u65e0\u9700\u8fdb\u884c\u8c03\u6574\u914d\u7f6e\uff0c\u4fdd\u6301\u9ed8\u8ba4\u5373\u53ef\u3002<\/p>\n

\u5982\u679c\u4f7f\u7528\u4e86\u4e00\u952e\u5b89\u88c5\u5305\u914d\u7f6e\u7684\u73af\u5883\uff0c\u53ef\u80fd\u5728\/etc\/logrotate.d \u4e0b\u5df2\u7ecf\u751f\u6210\u4e86\u6587\u4ef6nginx \uff0c\u5982\u679c\u6ca1\u6709\uff0c\u5219\u521b\u5efa\u8be5\u6587\u4ef6\uff1a<\/p>\n

\r\nvim \/etc\/logrotate.d\/nginx \r\n\/data\/weblogs\/*.log {\r\nweekly\r\nrotate 7\r\nmissingok\r\ndateext\r\nnocompress\r\nnotifempty\r\nsharedscripts\r\npostrotate\r\n[ -e \/var\/run\/nginx.pid ] && kill -USR1 `cat \/var\/run\/nginx.pid`\r\nendscript\r\n}\r\n<\/pre>\n

\u914d\u7f6e\u9009\u9879\u8bf4\u660e\uff1a<\/p>\n

\/data\/weblogs\/*.log # \u9700\u8981\u5207\u5272\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u53ef\u4ee5\u6307\u5b9a\u4e3a\u67d0\u4e2a\u6587\u4ef6\u540d\u8fdb\u884c\u5207\u5272<\/p>\n

weekly #\u6307\u5b9a\u8f6c\u50a8\u5468\u671f\u4e3a\u6bcf\u5468\uff0c\u5bf9\u5e94\u7684 daily\uff1a\u6307\u5b9a\u8f6c\u50a8\u5468\u671f\u4e3a\u6bcf\u5929\uff0cmonthly\uff1a\u6307\u5b9a\u8f6c\u50a8\u5468\u671f\u4e3a\u6bcf\u6708<\/p>\n

rotate 7 #\u6307\u5b9a\u65e5\u5fd7\u6587\u4ef6\u5220\u9664\u4e4b\u524d\u8f6c\u50a8\u7684\u6b21\u6570\uff0c0 \u6307\u6ca1\u6709\u5907\u4efd\uff0c7 \u6307\u4fdd\u75597 \u4e2a\u5907\u4efd<\/p>\n

missingok #\u5982\u679c\u6307\u5b9a\u7684\u76ee\u5f55\u4e0d\u5b58\u5728\uff0clogrotate\u4f1a\u62a5\u9519\uff0c\u6b64\u9879\u7528\u6765\u5173\u95ed\u62a5\u9519<\/p>\n

nocompress # \u8fd9\u91cc\u662f\u4e0d\u8fdb\u884c\u538b\u7f29\uff0c\u5982\u679c\u9700\u8981\u5c06\u5207\u5272\u7684\u65e5\u5fd7\u8fdb\u884c\u538b\u7f29\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3acompress <\/p>\n

notifempty #\u5982\u679c\u662f\u7a7a\u6587\u4ef6\u7684\u8bdd\uff0c\u4e0d\u8f6c\u50a8<\/p>\n

sharedscripts #\u6240\u6709\u7684\u65e5\u5fd7\u6587\u4ef6\u90fd\u8f6e\u8f6c\u5b8c\u6bd5\u540e\u7edf\u4e00\u6267\u884c\u4e00\u6b21\u811a\u672c<\/p>\n

postrotate\/endscript #\u5728\u8f6c\u50a8\u4ee5\u540e\u9700\u8981\u6267\u884c\u7684\u547d\u4ee4\u53ef\u4ee5\u653e\u5165\u8fd9\u4e2a\u5bf9\uff0c\u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u5fc5\u987b\u5355\u72ec\u6210\u884c<\/p>\n

postrotate \u4e2d\u7684\u5185\u5bb9\u5373\u4e3a\uff1anginx\u8fdb\u7a0b\u53d1\u9001USR1\u4fe1\u53f7\u4f7f\u5176\u91cd\u65b0\u6253\u5f00\u65e5\u5fd7\u5e76\u5199\u5165\uff0c\u4e0d\u4f1a\u91cd\u542f\u670d\u52a1\uff0c\u4e5f\u4e0d\u4f1a\u5bfc\u81f4\u6700\u65b0\u5199\u5165\u7684\u65e5\u5fd7\u4e22\u5931<\/p>\n

\u5982\u679c\u65e5\u5fd7\u5206\u7c7b\u5b58\u653e\u5230\u4e0d\u540c\u7684\u76ee\u5f55\u4e0b\u53ef\u4ee5\u8fd9\u6837\u8bbe\u7f6e\uff1a<\/p>\n

\r\n\/data\/weblogs\/*.log \r\n\/data\/weblogs\/cnyunwei\/*.log\r\n{\r\nweekly\r\nrotate 7\r\n.....\r\n<\/pre>\n
\u6d4b\u8bd5\u662f\u5426\u6b63\u786e\u6267\u884c<\/strong><\/span><\/div>\n
\r\n[root@aliyun weblogs]#\/usr\/sbin\/logrotate -f \/etc\/logrotate.d\/nginx\r\n<\/pre>\n

\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\u540e\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u65e5\u5fd7\u6587\u4ef6\u4e0b\u751f\u6210\u4e86www.susecui.cn.log-20160808 \u7684\u6587\u4ef6\uff0c\u5982\u679c\u662f\u5f00\u542f\u4e86\u538b\u7f29\uff0c\u5219\u4f1a\u751f\u6210www.susecui.cn.log-20160808.gz \u7684\u538b\u7f29\u6587\u4ef6<\/p>\n

\u521b\u5efa\u4efb\u52a1\u8ba1\u5212\u6267\u884c\u547d\u4ee4<\/strong><\/span><\/div>\n

\u5982\u679c\u662f\u8bbe\u7f6e\u4e86\u6bcf\u5929\u8fdb\u884c\u5207\u5272\u65e5\u5fd7\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u5355\u72ec\u8bbe\u7f6e\u8ba1\u5212\u4efb\u52a1\uff0c\u9ed8\u8ba4\u8bbe\u7f6e\u4e3a\u4e00\u5468\u5207\u5272\u7684\u60c5\u51b5\u4e0b\u4e0d\u9700\u8981\u8bbe\u7f6e\u8ba1\u5212\u4efb\u52a1\uff0clogrotate \u4e3b\u914d\u7f6e\u6587\u4ef6\u4e2d\u5df2\u7ecf\u5b9a\u4e49\u4e86\u6bcf\u5468\u4f1a\u8fdb\u884c\u8f6e\u8be2\u3002<\/p>\n

\r\ncrontab -e\r\n\r\n10 2 * * 6 \/usr\/sbin\/logrotate -f \/etc\/logrotate.d\/nginx\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

logrotate \u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u5728\/etc\/logrotate.conf \u4e3b\u914d\u7f6e\u6587\u4ef6\u65e0\u9700\u8fdb\u884c\u8c03\u6574\u914d\u7f6e\uff0c\u4fdd\u6301\u9ed8\u8ba4 […]<\/p>\n","protected":false},"author":1479,"featured_media":7920,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-161131","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\/161131","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\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=161131"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/161131\/revisions"}],"predecessor-version":[{"id":161589,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/161131\/revisions\/161589"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/7920"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=161131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=161131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=161131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}