{"id":1359,"date":"2021-08-02T00:40:57","date_gmt":"2021-08-01T15:40:57","guid":{"rendered":"https:\/\/ito-u-oti.com\/?p=1359"},"modified":"2021-08-02T00:41:00","modified_gmt":"2021-08-01T15:41:00","slug":"docker-nginx-logrotate","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=1359","title":{"rendered":"docker nginx\u30a4\u30e1\u30fc\u30b8\u306e\u30b3\u30f3\u30c6\u30ca\u5185\u3067logrotate\u3092\u8d77\u52d5\u3055\u305b\u308b"},"content":{"rendered":"\n<p>nginx\u30a4\u30e1\u30fc\u30b8\u30d9\u30fc\u30b9\u306edocker\u30b3\u30f3\u30c6\u30ca\u306b\u5bfe\u3057\u3066logrotate\u3092\u4f7f\u7528\u3057\u3066\u30ed\u30b0\u306e\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u884c\u3046\u5834\u5408\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u30ed\u30b0\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u30de\u30a6\u30f3\u30c8\u3055\u305b\u3001\u30db\u30b9\u30c8\u5074\u3067logrotate\u3092\u52d5\u304b\u3057\u3066\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3059\u308b<\/li><li>nginx\u30b3\u30f3\u30c6\u30ca\u5185\u3067logrotate\u3092\u52d5\u304b\u3057\u3001\u30ed\u30b0\u306e\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u30b3\u30f3\u30c6\u30ca\u5185\u3067\u5b8c\u7d50\u3055\u305b\u308b<\/li><\/ul>\n\n\n\n<p>\u306e\u3088\u3046\u306a\u65b9\u6cd5\u304c\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u524d\u8005\u306e\u5834\u5408\u306f\u3001\u30b3\u30f3\u30c6\u30ca\u5185\u306fnginx\u306b\u95a2\u3059\u308b\u3053\u3068\u3060\u3051\u304c\u52d5\u3044\u3066\u3044\u308b\u306e\u3067\u30b7\u30f3\u30d7\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<br>\u305f\u3060\u3001\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306e\u5f8c\u59cb\u672b\u306b\u95a2\u3057\u3066\u306f\u5e38\u306b\u30db\u30b9\u30c8\u5074\u3067\u610f\u8b58\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5f8c\u8005\u306e\u5834\u5408\u306f\u3001\u30b3\u30f3\u30c6\u30ca\u5185\u3067nginx\u3068\u306f\u5225\u306blogrotate\u3082\u8d77\u52d5\u3055\u305b\u308b\u3088\u3046\u306a\u30a4\u30e1\u30fc\u30b8\u306b\u306a\u308a\u307e\u3059\u3002<br>\u30ed\u30b0\u306e\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u307e\u3067\u542b\u3081\u3066\u5168\u90e8\u30b3\u30f3\u30c6\u30ca\u306e\u4e2d\u3067\u5b8c\u7d50\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5f8c\u8005\u306b\u3064\u3044\u3066\u306e\u8a2d\u5b9a\u306b\u95a2\u3059\u308b\u77e5\u898b\u3092\u8f09\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__1\" class=\"wp-block-heading\">\u6700\u7d42\u7684\u306aDockerfile\u306e\u5b8c\u6210\u5f62<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nFROM nginx:latest\n\n# copy to nginx settings\nCOPY .\/default.conf \/etc\/nginx\/conf.d\/\nCOPY .\/nginx.conf \/etc\/nginx\/\n\nRUN apt-get update\n\n##### rsyslog settings #####\nRUN apt -y install rsyslog\nCOPY .\/conf\/rsyslog\/50-default.conf \/etc\/rsyslog.d\/\nRUN update-rc.d rsyslog enable\n\n##### logrotate settings #####\nRUN apt -y install logrotate\n# nginx\u306elogrotate\u4ee5\u5916\u306f\u52d5\u304b\u3055\u306a\u3044\nRUN rm \/etc\/cron.daily\/passwd\nRUN rm \/etc\/cron.daily\/dpkg\nRUN rm \/etc\/cron.daily\/apt-compat\nRUN rm \/etc\/cron.daily\/exim4-base\n# copy to logrotate settings\nCOPY .\/conf\/logrotate\/nginx_rotate \/etc\/logrotate.d\/nginx\nCOPY .\/conf\/logrotate\/daily_crontab \/etc\/cron.d\/\nCOPY .\/conf\/logrotate\/status \/var\/lib\/logrotate\nRUN update-rc.d cron enable\n\nCMD service cron start &amp;amp;&amp;amp; touch \/etc\/crontab \/etc\/cron.d\/* &amp;amp;&amp;amp; service rsyslog start &amp;amp;&amp;amp; nginx -g 'daemon off;'\n<\/pre><\/div>\n\n\n<p>logrotate\u304c\u4e0a\u624b\u304f\u8d77\u52d5\u3057\u3066\u304f\u308c\u306a\u304b\u3063\u305f\u969b\u306e\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c8\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">logrotate\u304c\u52d5\u4f5c\u3057\u3066\u3044\u308b\u304b\u3092\u78ba\u8a8d\u3059\u308b\u65b9\u6cd5<\/h2>\n\n\n\n<p>rsyslog\u3067\u5b9f\u884c\u7d50\u679c\u3092\u30ed\u30b0\u306b\u51fa\u529b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>rsyslog\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/li><li><code>50-default.conf<\/code> \u3092\u7528\u610f\u3057\u3001\u30b3\u30f3\u30c6\u30ca\u306e\u4e2d\u306b\u683c\u7d0d\u3059\u308b<\/li><\/ul>\n\n\n\n<p><code>50-default.conf<\/code><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\ncron.*    \/var\/log\/cron.log\n\n<\/pre><\/div>\n\n\n<p>Dockerfile<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\n##### rsyslog settings #####\nRUN apt -y install rsyslog\nCOPY .\/conf\/rsyslog\/50-default.conf \/etc\/rsyslog.d\/\nRUN update-rc.d rsyslog enable\n\n<\/pre><\/div>\n\n\n<p>rsyslog\u306b\u3088\u3063\u3066\u3001cron\u304c\u5b9f\u884c\u3055\u308c\u305f\u969b\u306bcron.log\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u51fa\u529b\u30ed\u30b0\u306e\u4f8b<\/p>\n\n\n\n<p><code>\/var\/log\/cron.log<\/code><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nAug  1 15:25:00 b3f825fd777a CRON&#x5B;7148]: (root) CMD (test -x \/usr\/sbin\/anacron || ( cd \/ &amp;amp;&amp;amp; run-parts --report \/etc\/cron.daily ) &gt;&gt; \/var\/log\/daily_crontab.txt 2&gt;&gt; \/var\/log\/daily_crontab_error.txt)\n<\/pre><\/div>\n\n\n<h2 id=\"outline__3\" class=\"wp-block-heading\">logrotate\u304c\u4e0a\u624b\u304f\u56de\u8ee2\u3057\u306a\u3044\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c8<\/h2>\n\n\n\n<h3 id=\"outline__3_1\" class=\"wp-block-heading\">nginx\u306elogrotate\u3088\u308a\u524d\u306b\u8d77\u52d5\u3059\u308bcron\u30b8\u30e7\u30d6\u3067\u52d5\u4f5c\u304c\u6b62\u307e\u3063\u3066\u3044\u305f<\/h3>\n\n\n\n<p>cron.daily\u306e\u4e2d\u306enginx\u4ee5\u5916\u306e\u30b8\u30e7\u30d6\u306e\u5b9a\u7fa9\u3092\u524a\u9664\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>Dockerfile<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# nginx\u306elogrotate\u4ee5\u5916\u306f\u52d5\u304b\u3055\u306a\u3044\nRUN rm \/etc\/cron.daily\/passwd\nRUN rm \/etc\/cron.daily\/dpkg\nRUN rm \/etc\/cron.daily\/apt-compat\nRUN rm \/etc\/cron.daily\/exim4-base\n\n<\/pre><\/div>\n\n\n<h3 id=\"outline__3_2\" class=\"wp-block-heading\">cron\u306e\u8a2d\u5b9a\u304c\u52d5\u4f5c\u3057\u306a\u3044<\/h3>\n\n\n\n<p>cron\u306e\u8a2d\u5b9a\u5024\u3092\u8a2d\u5b9a\u3057\u305f\u306e\u306b\u52d5\u4f5c\u305b\u305a\u3001\u5168\u3066*\u306e\u6bce\u5206\u8a2d\u5b9a\u3060\u3068\u52d5\u3044\u305f\u305f\u3081\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bcron\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\n* *\t    * * *\troot\ttest -x \/usr\/sbin\/anacron || ( cd \/ &amp;amp;&amp;amp; run-parts --report \/etc\/cron.daily ) &gt;&gt; \/var\/log\/daily_crontab.txt 2&gt;&gt; \/var\/log\/daily_crontab_error.txt\n\n<\/pre><\/div>\n\n\n<p>\u6bce\u5206\u30b8\u30e7\u30d6\u304c\u8d77\u52d5\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u4e0a\u3067\u3001nginx\u306elogrotate\u306e\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u8a2d\u5b9a\u306e\u65b9\u3067\u65e5\u4ed8\u304c\u5909\u308f\u3063\u305f\u3089\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3055\u308c\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>nginx\u306elogrotate\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\n\/var\/log\/nginx\/*.log {\n        daily\n        maxsize 1\n        missingok\n        notifempty\n        rotate 180\n        dateext\n        compress\n        delaycompress\n        create 0640 www-data adm\n        sharedscripts\n        postrotate\n                if &#x5B; -f \/var\/run\/nginx.pid ]; then\n                        kill -USR1 `cat \/var\/run\/nginx.pid`\n                fi\n        endscript\n}\n\n<\/pre><\/div>\n\n\n<h3 id=\"outline__3_3\" class=\"wp-block-heading\">\u30b3\u30f3\u30c6\u30ca\u3092\u52d5\u304b\u3057\u305f\u5f53\u65e5\u306erotate\u304c\u3055\u308c\u306a\u3044<\/h3>\n\n\n\n<p>cron \u3092\u8d77\u52d5\u3057\u305f\u76f4\u5f8c\u306b\u4f5c\u6210\u3055\u308c\u305f status \u3067\u306f\u8d77\u52d5\u3057\u305f\u65e5\u3067\u767b\u9332\u3055\u308c\u308b\u305f\u3081\u3001daily \u3067 logrotate \u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u7fcc\u65e5\u304b\u3089 rotate \u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u3002<br>\u30b3\u30f3\u30c6\u30ca\u304c\u518d\u8d77\u52d5\u3055\u308c\u308b\u3053\u3068\u3082\u60f3\u5b9a\u3059\u308b\u3068\u3001\u8d77\u52d5\u3057\u305f\u65e5\u304b\u3089 logrotate \u3092\u52d5\u4f5c\u3055\u305b\u308b\u3088\u3046\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br>\u306a\u306e\u3067\u3001\u53e4\u3044\u65e5\u4ed8\u3067\u4f5c\u6210\u3055\u308c\u305f status \u3092\u30b3\u30f3\u30c6\u30ca\u306e\u4e2d\u306b\u683c\u7d0d\u3059\u308b\u3053\u3068\u3067\u5f53\u65e5\u3082rotate\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>status\u30d5\u30a1\u30a4\u30eb<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\nlogrotate state -- version 2\n&quot;\/var\/log\/nginx\/error.log&quot; 1999-4-12-3:0:0\n&quot;\/var\/log\/dpkg.log&quot; 1999-4-12-3:0:0\n&quot;\/var\/log\/apt\/term.log&quot; 1999-4-12-3:0:0\n&quot;\/var\/log\/apt\/history.log&quot; 1999-4-12-3:0:0\n&quot;\/var\/log\/alternatives.log&quot; 1999-4-12-3:0:0\n&quot;\/var\/log\/wtmp&quot; 1999-4-12-3:0:0\n&quot;\/var\/log\/btmp&quot; 1999-4-12-3:0:0\n&quot;\/var\/log\/exim4\/paniclog&quot; 1999-4-12-3::0\n&quot;\/var\/log\/nginx\/access.log&quot; 1999-4-12-3:0:0\n&quot;\/var\/log\/exim4\/rejectlog&quot; 1999-4-12-3::0\n&quot;\/var\/log\/exim4\/mainlog&quot; 1999-4-12-3::0\n\n<\/pre><\/div>\n\n\n<p>Dockerfile<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\nCOPY .\/conf\/logrotate\/status \/var\/lib\/logrotate\n\n<\/pre><\/div>\n\n\n<h3 id=\"outline__3_4\" class=\"wp-block-heading\">\u305d\u308c\u3067\u3082logrotate\u304c\u52d5\u4f5c\u3057\u306a\u3044<\/h3>\n\n\n\n<p>Cron \u306f (\u5c11\u306a\u304f\u3068\u3082 Debian \u3067\u306f) 1 \u3064\u4ee5\u4e0a\u306e\u30cf\u30fc\u30c9\u30ea\u30f3\u30af\u3092\u6301\u3064 crontab \u3092\u5b9f\u884c\u3057\u307e\u305b\u3093\u3002<br>Docker\u306f\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u30ea\u30f3\u30af\u304c\u8907\u6570\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br>\u305d\u306e\u305f\u3081\u3001\u30b9\u30bf\u30fc\u30c8\u30a2\u30c3\u30d7\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u30bf\u30c3\u30c1\u3057\u3066\u3001\u30ea\u30f3\u30af\u3092\u5207\u65ad\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3088\u3063\u3066\u3001Dockerfile\u306eCMD\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u4e0b\u306etouch\u30b3\u30de\u30f3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\ntouch \/etc\/crontab \/etc\/cron.d\/*\n\n<\/pre><\/div>\n\n\n<h2 id=\"outline__4\" class=\"wp-block-heading\">github<\/h2>\n\n\n\n<p>\u5168\u5bb9\u306f\u3053\u3061\u3089\u306b\u8f09\u305b\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/itouoti12\/logrotate-in-nginx-docker\">https:\/\/github.com\/itouoti12\/logrotate-in-nginx-docker<\/a><\/p>\n\n\n\n<h2 id=\"outline__5\" class=\"wp-block-heading\">\u53c2\u8003<\/h2>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/34962020\/cron-and-crontab-files-not-executed-in-docker\">Cron and Crontab files not executed in Docker<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/46323978\/logrotate-nginx-logs-not-rotating-inside-docker-container\">Logrotate &#8211; nginx logs not rotating inside docker container<\/a><\/p>\n\n\n\n<p>proxy\u306a\u3069\u3067logrotate\u3084rsyslog\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u306a\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/debian-offline-install\/\">Debian\u7cfb\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30aa\u30d5\u30e9\u30a4\u30f3\u30a4\u30f3\u30b9\u30c8\u30fc\u30e9\u3092\u4f5c\u308b<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>nginx\u30a4\u30e1\u30fc\u30b8\u30d9\u30fc\u30b9\u306edocker\u30b3\u30f3\u30c6\u30ca\u306b\u5bfe\u3057\u3066logrotate\u3092\u4f7f\u7528\u3057\u3066\u30ed\u30b0\u306e\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1361,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307],"tags":[289,309,308],"class_list":["post-1359","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nginx","tag-docker","tag-logrotate","tag-nginx"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1359"}],"version-history":[{"count":5,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1359\/revisions"}],"predecessor-version":[{"id":1365,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1359\/revisions\/1365"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/1361"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}