設定ファイルの場所
/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回実行される。