{"id":151,"date":"2022-05-16T00:35:34","date_gmt":"2022-05-15T16:35:34","guid":{"rendered":"https:\/\/frogvps.com\/?p=151"},"modified":"2022-05-18T08:40:20","modified_gmt":"2022-05-18T00:40:20","slug":"logrotate%e6%97%a5%e5%bf%97%e8%bd%ac%e5%82%a8%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/frogvps.com\/?p=151","title":{"rendered":"logrotate\u65e5\u5fd7\u8f6c\u50a8\u6559\u7a0b"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">logrotate \u4ecb\u7ecd<\/h2>\n\n\n\n<p>\u5f88\u591a\u670d\u52a1\u90fd\u6709\u81ea\u5df1\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u4f46\u662f\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb\uff0c\u65e5\u5fd7\u8d8a\u6765\u8d8a\u591a\uff0c\u786c\u76d8\u7a7a\u95f4\u5c31\u4f1a\u88ab\u6491\u6ee1\u3002logrotate\u662f\u7cfb\u7edf\u81ea\u5e26\u7684\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u81ea\u52a8\u628a\u65e5\u5fd7\u505a\u8f6c\u50a8\u3002\u4e5f\u5c31\u662f\u6bcf\u9694\u4e00\u6bb5\u81ea\u52a8\u5730\u5bf9\u65e5\u5fd7\u8fdb\u884c\u6eda\u52a8\u538b\u7f29\u548c\u5220\u9664\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">logrotate \u914d\u7f6e<\/h2>\n\n\n\n<p><strong>\u8f6f\u4ef6\u5305<\/strong>\uff1alogrotate<\/p>\n\n\n\n<p><strong>\u76f8\u5173\u6587\u4ef6<\/strong>\uff1a<\/p>\n\n\n\n<p>\u8ba1\u5212\u4efb\u52a1\uff1a\/etc\/cron.daily\/logrotate <\/p>\n\n\n\n<p>\u7a0b\u5e8f\u6587\u4ef6\uff1a\/usr\/sbin\/logrotate <\/p>\n\n\n\n<p>\u914d\u7f6e\u6587\u4ef6\uff1a \/etc\/logrotate.conf \/etc\/logrotate.d <\/p>\n\n\n\n<p>\u65e5\u5fd7\u6587\u4ef6\uff1a\/var\/lib\/logrotate\/logrotate.status<\/p>\n\n\n\n<p><strong>\u914d\u7f6e\u6587\u4ef6\u4e3b\u8981\u53c2\u6570\u5982\u4e0b\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u914d\u7f6e\u53c2\u6570<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td>compress<\/td><td>\u901a\u8fc7gzip\u538b\u7f29\u8f6c\u50a8\u4ee5\u540e\u7684\u65e5\u5fd7<\/td><\/tr><tr><td>nocompress<\/td><td>\u4e0d\u538b\u7f29<\/td><\/tr><tr><td>copytruncate<\/td><td>\u7528\u4e8e\u8fd8\u5728\u6253\u5f00\u4e2d\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u628a\u5f53\u524d\u65e5\u5fd7\u5907\u4efd\u5e76\u622a\u65ad<\/td><\/tr><tr><td>nocopytruncate<\/td><td>\u5907\u4efd\u65e5\u5fd7\u6587\u4ef6\u4f46\u662f\u4e0d\u622a\u65ad<\/td><\/tr><tr><td>create mode owner group<\/td><td>\u8f6c\u50a8\u6587\u4ef6\uff0c\u4f7f\u7528\u6307\u5b9a\u7684\u6743\u9650\uff0c\u6240\u6709\u8005\uff0c\u6240\u5c5e\u7ec4\u521b\u5efa\u65b0\u7684\u65e5\u5fd7\u6587\u4ef6<\/td><\/tr><tr><td>nocreate<\/td><td>\u4e0d\u5efa\u7acb\u65b0\u7684\u65e5\u5fd7\u6587\u4ef6<\/td><\/tr><tr><td>delaycompress<\/td><td>\u548c compress \u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u8f6c\u50a8\u7684\u65e5\u5fd7\u6587\u4ef6\u5230\u4e0b\u4e00\u6b21\u8f6c\u50a8\u65f6\u624d\u538b\u7f29<\/td><\/tr><tr><td>nodelaycompress<\/td><td>\u8986\u76d6 delaycompress \u9009\u9879\uff0c\u8f6c\u50a8\u540c\u65f6\u538b\u7f29<\/td><\/tr><tr><td>errors address<\/td><td>\u4e13\u50a8\u65f6\u7684\u9519\u8bef\u4fe1\u606f\u53d1\u9001\u5230\u6307\u5b9a\u7684Email \u5730\u5740<\/td><\/tr><tr><td>ifempty<\/td><td>\u5373\u4f7f\u662f\u7a7a\u6587\u4ef6\u4e5f\u8f6c\u50a8\uff0c\u6b64\u4e3a\u9ed8\u8ba4\u9009\u9879<\/td><\/tr><tr><td>notifempty<\/td><td>\u5982\u679c\u662f\u7a7a\u6587\u4ef6\u7684\u8bdd\uff0c\u4e0d\u8f6c\u50a8<\/td><\/tr><tr><td>mail address<\/td><td>\u628a\u8f6c\u50a8\u7684\u65e5\u5fd7\u6587\u4ef6\u53d1\u9001\u5230\u6307\u5b9a\u7684E-mail \u5730\u5740<\/td><\/tr><tr><td>nomail<\/td><td>\u8f6c\u50a8\u65f6\u4e0d\u53d1\u9001\u65e5\u5fd7\u6587\u4ef6<\/td><\/tr><tr><td>olddir directory<\/td><td>\u8f6c\u50a8\u540e\u7684\u65e5\u5fd7\u6587\u4ef6\u653e\u5165\u6307\u5b9a\u76ee\u5f55\uff0c\u5fc5\u987b\u548c\u5f53\u524d\u65e5\u5fd7\u6587\u4ef6\u5728\u540c\u4e00\u4e2a\u6587\u4ef6 \u7cfb\u7edf<\/td><\/tr><tr><td>noolddir<\/td><td>\u8f6c\u50a8\u540e\u7684\u65e5\u5fd7\u6587\u4ef6\u548c\u5f53\u524d\u65e5\u5fd7\u6587\u4ef6\u653e\u5728\u540c\u4e00\u4e2a\u76ee\u5f55\u4e0b<\/td><\/tr><tr><td>prerotate\/endscript<\/td><td>\u5728\u8f6c\u50a8\u4ee5\u524d\u9700\u8981\u6267\u884c\u7684\u547d\u4ee4\uff0c\u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u5fc5\u987b\u5355\u72ec\u6210\u884c<\/td><\/tr><tr><td>postrotate\/endscript<\/td><td>\u5728\u8f6c\u50a8\u4ee5\u540e\u9700\u8981\u6267\u884c\u7684\u547d\u4ee4\uff0c\u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u5fc5\u987b\u5355\u72ec\u6210\u884c<\/td><\/tr><tr><td>daily<\/td><td>\u6307\u5b9a\u8f6c\u50a8\u5468\u671f\u4e3a\u6bcf\u5929<\/td><\/tr><tr><td>weekly<\/td><td>\u6307\u5b9a\u8f6c\u50a8\u5468\u671f\u4e3a\u6bcf\u5468<\/td><\/tr><tr><td>monthly<\/td><td>\u6307\u5b9a\u8f6c\u50a8\u5468\u671f\u4e3a\u6bcf\u6708<\/td><\/tr><tr><td>rotate count<\/td><td>\u6307\u5b9a\u65e5\u5fd7\u6587\u4ef6\u5220\u9664\u4e4b\u524d\u8f6c\u50a8\u7684\u6b21\u6570\uff0c0 \u6307\u6ca1\u6709\u5907\u4efd\uff0c5 \u6307\u4fdd\u75595 \u4e2a\u5907\u4efd<\/td><\/tr><tr><td>tabooext [+] list<\/td><td>\u8ba9logrotate\u4e0d\u8f6c\u50a8\u6307\u5b9a\u6269\u5c55\u540d\u7684\u6587\u4ef6\uff0c\u7f3a\u7701\u7684\u6269\u5c55\u540d\u662f\uff1a.rpm-orig,.rpmsave, v, \u548c ~<\/td><\/tr><tr><td>size size<\/td><td>\u5f53\u65e5\u5fd7\u6587\u4ef6\u5230\u8fbe\u6307\u5b9a\u7684\u5927\u5c0f\u65f6\u624d\u8f6c\u50a8\uff0cbytes(\u7f3a\u7701)\u53caKB\u6216MB<\/td><\/tr><tr><td>sharedscripts<\/td><td>\u9ed8\u8ba4\uff0c\u5bf9\u6bcf\u4e2a\u8f6c\u50a8\u65e5\u5fd7\u8fd0\u884cprerotate\u548cpostrotate\u811a\u672c\uff0c\u65e5\u5fd7\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\u4f20\u9012\u7ed9\u811a\u672c\u3002 \u8fd9\u610f\u5473\u7740\u5355\u4e2a\u811a\u672c\u53ef\u4ee5\u9488\u5bf9\u4e0e\u591a\u4e2a\u6587\u4ef6\u5339\u914d\u7684\u65e5\u5fd7\u6587\u4ef6\u6761\u76ee\u591a\u6b21\u8fd0\u884c\uff08\u4f8b\u5982\/ var \/ log \/ news \/*.example\uff09\u3002 \u5982\u679c\u6307\u5b9a\u6b64\u9879sharedscripts\uff0c\u5219\u65e0\u8bba\u6709\u591a\u5c11\u4e2a\u65e5\u5fd7\u4e0e\u901a\u914d\u7b26\u6a21\u5f0f\u5339\u914d\uff0c\u811a\u672c\u90fd\u53ea\u4f1a\u8fd0\u884c\u4e00\u6b21<\/td><\/tr><tr><td>nosharedscripts<\/td><td>\u9488\u5bf9\u6bcf\u4e00\u4e2a\u8f6c\u50a8\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u90fd\u6267\u884c\u4e00\u6b21prerotate \u548c postrotate\u811a\u672c\uff0c\u6b64\u4e3a\u9ed8\u8ba4\u503c<\/td><\/tr><tr><td>missingok<\/td><td>\u5982\u679c\u65e5\u5fd7\u4e0d\u5b58\u5728\uff0c\u4e0d\u63d0\u793a\u9519\u8bef\uff0c\u7ee7\u7eed\u5904\u7406\u4e0b\u4e00\u4e2a<\/td><\/tr><tr><td>nomissingok<\/td><td>\u5982\u679c\u65e5\u5fd7\u4e0d\u5b58\u5728\uff0c\u63d0\u793a\u9519\u8bef\uff0c\u6b64\u4e3a\u9ed8\u8ba4\u503c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u8bbe\u7f6enginx\u7684\u65e5\u5fd7\u8f6c\u50a8<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u6587\u4ef6\u540d\u81ea\u5df1\u5b9a\uff0c\u5173\u952e\u662f\u91cc\u9762\u7684\u5185\u5bb9<br>vim \/etc\/logrotate.d\/nginx<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u6bcf\u5468\u8f6c\u50a8\u4e00\u6b21\uff0c\u4fdd\u75594\u5468\u7684\u5907\u4efd\uff0c\u5982\u679c\u65e5\u5fd7\u4e0d\u5b58\u5728\u4e0d\u62a5\u9519\uff0c\u5ef6\u8fdf\u538b\u7f29\u8f6c\u50a8\u7684\u6587\u4ef6\u3002\u751f\u6210\u8f6c\u50a8\u65e5\u5fd7\u7684\u6743\u9650\u662f644\u3001\u6240\u6709\u8005nginx\u3001\u6240\u5c5e\u7ec4nginx\u3002\u8f6c\u50a8\u5b8c\u6267\u884c\u811a\u672c\uff1a\u91cd\u65b0\u6253\u5f00\u4e00\u4e2a\u65b0\u7684nginx\u65e5\u5fd7\u6587\u4ef6\u3002\uff08\u8fd9\u91cc\u7684\u4fe1\u53f7USER1\u7684\u542b\u4e49\u662f Reopen log files\uff0c\u8be6\u89c1nginx\u7684\u5e2e\u52a9\u6587\u6863\uff09\n\/var\/log\/nginx\/*.log {\n  weekly\n  rotate 4\n  missingok\n  compress\n  delaycompress\n  notifempty\n  create 644 nginx nginx\n  postrotate\n  size 1M #\u65e5\u5fd7\u8fbe\u52301M\u4f1a\u8f6c\u50a8\uff0c\u6211\u4e3a\u4e86\u6d4b\u8bd5\u624b\u52a8\u8f6c\u50a8\u6548\u679c\u6240\u4ee5\u8bbe\u7f6e\u4e861M\uff0c\u5b9e\u9645\u53ef\u4ee5\u4e0d\u8bbe\u7f6e\n &nbsp;  if &#91; -f \/run\/nginx.pid ]; then\n &nbsp; &nbsp;  kill -USR1 `cat \/run\/nginx.pid`\n &nbsp;  fi\n  endscript\n}\n\u200b\n#\u91cd\u542f\u670d\u52a1\nsystemctl restart logrotate<\/code><\/pre>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u5bf9\u6307\u5b9a\u7684\u65e5\u5fd7\u8fdb\u884c\u624b\u52a8\u8f6c\u50a8<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>logrotate \/etc\/logrotate.d\/nginx<br>ll \/var\/log\/nginx\/<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xiaoqinwa\/frogpic\/img\/20220516a1.jpg\" alt=\"\"\/><figcaption>\u5982\u679c\u914d\u7f6e\u6ca1\u95ee\u9898\uff0c\u53ef\u4ee5\u770b\u5230\u65e5\u5fd7\u8f6c\u50a8\u6210\u529f<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>logrotate \u4ecb\u7ecd \u5f88\u591a\u670d\u52a1\u90fd\u6709\u81ea\u5df1\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u4f46\u662f\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb\uff0c\u65e5\u5fd7\u8d8a\u6765\u8d8a\u591a\uff0c\u786c\u76d8\u7a7a\u95f4\u5c31\u4f1a\u88ab\u6491\u6ee1\u3002logrotate\u662f\u7cfb\u7edf\u81ea\u5e26\u7684\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u81ea\u52a8\u628a\u65e5\u5fd7\u505a\u8f6c\u50a8\u3002\u4e5f\u5c31\u662f\u6bcf\u9694\u4e00\u6bb5\u81ea\u52a8\u5730\u5bf9\u65e5\u5fd7\u8fdb\u884c\u6eda\u52a8\u538b\u7f29\u548c\u5220\u9664\u3002 logrotate \u914d\u7f6e &#8230;<\/p>\n","protected":false},"author":1,"featured_media":143,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[15,34],"topic":[],"class_list":["post-151","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-linux","tag-34"],"_links":{"self":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=151"}],"version-history":[{"count":2,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":153,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/151\/revisions\/153"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/media\/143"}],"wp:attachment":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=151"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}