2013-12-15

CentOS 6.3 で確認した Apache アクセスログのローテーション設定

CentOS 6.3 でのお話。


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 を実行する


となる。

apache アクセスログの圧縮

# less /etc/httpd/conf/httpd.conf
CustomLog "| /usr/sbin/rotatelogs /var/log/httpd/access_log.%Y%m%d 86400 540" combined


上記のように出力されているapacheアクセスログファイルを圧縮するスクリプト

#!/bin/bash
LOGDATE=`date -d '1 days ago' +'%Y%m%d'`
gzip /var/log/httpd/access_log.$LOGDATE


このスクリプトをcronで仕込めばOK。


参考にさせてもらったところ
■15分で理解するApacheのログローテート
http://wimax.blog64.fc2.com/blog-entry-91.html

Chatの「メッセージは投稿者によって削除されました」を非表示にする方法

Chrome拡張機能を自作してやってみよう! ♪できるかな できるかな ・・・ 無理ぽ (´・ω・`) iframeの中に、実際のメッセージのやり取りが表示されるので、 $(function(){ $('iframe[name^="spa...