スキップしてメイン コンテンツに移動

投稿

12月, 2013の投稿を表示しています

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 infor...

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