httpd及tomcat6日志过大问题优化记录


一、httpd日志处理

vi /usr/local/apache/conf/httpd.conf

查找

ErrorLog "logs/error_log

替换为

ErrorLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/error_%Y%m%d.log 86400 540"

查找

CustomLog "logs/access_log" common

替换为

CustomLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/access_%Y%m%d.log 86400 540" combined

:wq  #保存退出

rotatelogs所在的路径是/usr/local/apache/bin/rotatelogs

log文件在/usr/local/apache/logs/下

二、tomcat6日志处理

安装cronolog

(1).直接用yum安装 

#wget http://mirrors.kernel.org/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

#rpm –ivh epel-release-6-8.noarch.rpm

# yum install -y cronolog

(2).修改tomcat启动文件catalina.sh

修改前备份一个文件

# cp /usr/local/tomcat6/bin/catalina.sh /usr/local/tomcat6/bin/catalina.sh.bak

# vim /usr/local/tomcat6/bin/catalina.sh

A、将touch "$CATALINA_OUT"行注释掉。


B、将

org.apache.catalina.startup.Bootstrap "$@" start \  >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &  替换成:

org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \

| cronolog "$CATALINA_BASE"/logs/catalina.out.%Y-%m-%d >> /dev/null &  

重启tomcat,则下次将会在catalina.out后面加上年月日,从而按日进行日志输出。