13
15

More than 5 years have passed since last update.

【Linux】logrotate

Last updated at Posted at 2014-10-20

設定ファイルの場所

/etc/logrotate.confに共通設定、/etc/logrotate.d/配下に個別の設定を書く。
logrotate.d配下の設定がデフォルト設定をオーバーライドするイメージ。

例えば、apacheのログのローテーションをしたい場合は、logrotate.d配下にapache用のファイルを作成して、個別設定を書き込む。

設定例
/etc/httpd/logs/access_log
/etc/httpd/logs/error_log {
      weekly
      rotate 4
}

項目の意味

項目 意味
daily,weekly,monthly それぞれ毎日(0時)、週毎、月毎。
rotate n n回分保存。weeklyで、rotate 4なら4週間分保存する。
dateext ログファイル末尾につく数値の代わりに日付(YYYYMMDD)がつく
compress ローテーションしたログを圧縮
notifempty ログファイルが空ならローテートしない
missingok 対象ファイルが存在しなくてもエラーを出さずに処理続行

logrotateの実行タイミング

/etc/cron.daily内にlogrotate用のshellがあり毎日1回実行される。

13
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
15