ログのローテーション

/etc/logrotet.d以下にファイル追加、もしくは既存ファイルに追記すればOK

[root@hoge-dev /var/lib]# cd /etc/logrotate.d
[root@hoge-dev /etc/logrotate.d]# ll
合計 84
-rw-r--r-- 1 root root 144  1月  6  2007 acpid
-rw-r--r-- 1 root root 288 11月 12  2007 conman
-rw-r--r-- 1 root root  71  5月 25  2008 cups
-rw-r--r-- 1 root root 167  2月 18 21:31 hoge ←新規作成
-rw-r--r-- 1 root root 167  2月 18 21:31 httpd ←もしくは追記
-rw-r--r-- 1 root root 571  1月  7  2007 mgetty
-rw-r--r-- 1 root root 789  4月  1  2009 mysql
-rw-r--r-- 1 root root 136  3月 15  2007 ppp
-rw-r--r-- 1 root root 323  1月  6  2007 psacct
-rw-r--r-- 1 root root  61  5月 25  2008 rpm
-rw-r--r-- 1 root root 232  1月 21  2009 samba
-rw-r--r-- 1 root root 306  5月 25  2008 syslog
-rw-r--r-- 1 root root 100  8月 20 22:55 yum

新規追加

[root@hoge-dev /etc/logrotate.d]# cat hoge
/var/log/httpd/*log { ←ローテーションさせたいパスを記述
    missingok      以下は各種設定
    notifempty      デフォルトは/etc/logrotate.conf参照
    sharedscripts
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}

追記する場合はこのような感じで

[root@hoge-dev /etc/logrotate.d]# cat httpd
/var/log/httpd/*log /var/www/*/*/logs/*log /var/www/*/*/*/*/symfony/log/*.log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}



ローテーションはcron.dailyで実行されるが、/etc/logrotate.confを実行することでも直接実行できる

[root@hoge-dev /var/lib]# logrotate /etc/logrotate.conf

ローテーション状況は/var/lib/logrotate.statusで確認できる

[root@hoge-dev /var/lib]# cat logrotate.status
logrotate state -- version 2
/var/log/acpid 2009-4-20
/var/log/conman/* 2009-4-20
/var/log/cups/error_log 2009-6-9
/var/log/mgetty.log.tty[^.] 2009-4-20
〜(略)〜
/var/log/httpd/ssl_request_log 2009-8-21
/var/log/samba/nmbd.log 2010-2-14
/var/log/samba/smbd.log 2010-2-14

参考)/etc/logrotate.conf
・logrotate.dをincludeしている
・1週間周期で4週分保存 など

[root@hoge-dev etc]# cat 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

# 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 -- we'll rotate them here
/var/log/wtmp {
    monthly
    minsize 1M
    create 0664 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.