Upgrade to Pro — share decks privately, control downloads, hide ads and more …

how logrotate works

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

how logrotate works

Avatar for tokuhirom

tokuhirom

April 11, 2020
Tweet

Other Decks in Technology

Transcript

  1. 本スライドでは以下のような設定を想定 /var/log/nginx/*log { daily # 一日一回 rotate(hourly, monthly, yearly なども指定可能)

    missingok # 元ファイルがなくてもエラーにしない rotate 1 # 1世代を保持 compress # 古いファイルを圧縮する delaycompress # mv した回の次の rotate のタイミングで圧縮する notifempty # ファイルが空だったら rotate しない create 640 www www # www ユーザーで、file mode 640 で新規ファイルを作成 sharedscripts # パターンにマッチするファイルが複数個あっても一回しか # postrotate が実行されないようにする postrotate # rotate 後に、以下のスクリプトを実行する [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid` endscript } /etc/logrotate.d/nginx 等に配置。
  2. nginx access.log-20200409 logrotate kill –USR1 $(cat /var/run/nginx.pid) access.log access.log-20200408 access.log-20200407.gz

    logrotate が nginx にシグナル SIGUSR1 を送信する。 nginx は “access.log” を開き直す。以後は新しいファイルにログが書き込まれ る。