Apacheをyumでインストールすると、Apacheログのローテート設定ファイルが作られる。
# less /etc/logrotate.d/httpd
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
delaycompress
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
}
logrotateはcronで実行されるようになっている。
# ls /etc/cron.daily logrotate
このlogrotateの中身を確認すると
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
となっていて、以下の /etc/logrotate.conf の定義をもとにログをローテートしている。
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}
# system-specific logs may be also be configured here.
というわけで、CentOS 6.3 デフォルトの場合、Apacheのログファイルは
weekly
週次にローテーション。
rotate 4
4世代前まで残す。
dateext
ローテーション後のログファイル末尾につく数値の代わりに、日付(-YYYYMMDD)をつける。
#compress
圧縮しない。
missingok
ログファイルが存在しない場合にエラーを出力しない。
notifempty
ログファイルが空の場合ローテーションしない。
sharedscripts
ログファイルを複数指定した場合、それぞれpostrotate、prerotate内のコマンドを実行する。
delaycompress
次回のログローテーションサイクルになるまで圧縮しない。
※compressが指定されていないため、次回のログローテーションサイクルになっても、圧縮されない。
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
ログローテーション後に、httpd reload を実行する
となる。