默认情况下,tomcat的catalina.out日志文件是没有像其它日志一样,按日期进行分割,而是全部输出全部写入到一个catalina.out,这样日积月累就会造成.out日志越来越大,给管理造成了不便,为了实现像其它日志文件一样按日期归档,这里我们采用cronolog来完成日志分割。
一、安装cronolog
YUM 安装 使用cronolog包实现按日期分割catalina.out日志文件yum install cronolog
或是 源码安装
1、下载(最新版本)wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
2、解压缩
tar zxvf cronolog-1.6.2.tar.gz
3、进入cronolog安装文件所在目录
cd cronolog-1.6.2
4、运行安装
./configuremakemake install
5、查看cronolog安装后所在目录(验证安装是否成功)
which cronolog/usr/sbin/cronolog
二、修改bin/catalina.sh文件 标红的为修改的内容,
具体如下:shift
touch “$CATALINA_OUT” if [ “$1” = “-security” ] ; then if [ $have_tty -eq 1 ]; then echo “Using Security Manager” fi shift eval “\”$_RUNJAVA\”” “\”$LOGGING_CONFIG\”” $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs=”\”$JAVA_ENDORSED_DIRS\”” -classpath “\”$CLASSPATH\”” \ -Djava.security.manager \ -Djava.security.policy==”\”$CATALINA_BASE/conf/catalina.policy\”” \ -Dcatalina.base=”\”$CATALINA_BASE\”” \ -Dcatalina.home=”\”$CATALINA_HOME\”” \ -Djava.io.tmpdir=”\”$CATALINA_TMPDIR\”” \org.apache.catalina.startup.Bootstrap “$@” start \>> “$CATALINA_OUT” 2>&1 “&”else
eval “\”$_RUNJAVA\”” “\”$LOGGING_CONFIG\”” $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs=”\”$JAVA_ENDORSED_DIRS\”” -classpath “\”$CLASSPATH\”” \ -Dcatalina.base=”\”$CATALINA_BASE\”” \ -Dcatalina.home=”\”$CATALINA_HOME\”” \ -Djava.io.tmpdir=”\”$CATALINA_TMPDIR\”” \org.apache.catalina.startup.Bootstrap “$@” start \>> “$CATALINA_OUT” 2>&1 “&”fi
改为:
shift# touch “$CATALINA_OUT” 注释掉 if [ “$1” = “-security” ] ; then if [ $have_tty -eq 1 ]; then echo “Using Security Manager” fi shift eval “\”$_RUNJAVA\”” “\”$LOGGING_CONFIG\”” $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs=”\”$JAVA_ENDORSED_DIRS\”” -classpath “\”$CLASSPATH\”” \ -Djava.security.manager \ -Djava.security.policy==”\”$CATALINA_BASE/conf/catalina.policy\”” \ -Dcatalina.base=”\”$CATALINA_BASE\”” \ -Dcatalina.home=”\”$CATALINA_HOME\”” \ -Djava.io.tmpdir=”\”$CATALINA_TMPDIR\”” \org.apache.catalina.startup.Bootstrap “$@” start 2>&1 | /usr/sbin/cronolog “$CATALINA_BASE”/logs/catalina.%Y-%m-%d.out >> /dev/null &else
eval “\”$_RUNJAVA\”” “\”$LOGGING_CONFIG\”” $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs=”\”$JAVA_ENDORSED_DIRS\”” -classpath “\”$CLASSPATH\”” \ -Dcatalina.base=”\”$CATALINA_BASE\”” \ -Dcatalina.home=”\”$CATALINA_HOME\”” \ -Djava.io.tmpdir=”\”$CATALINA_TMPDIR\”” \org.apache.catalina.startup.Bootstrap “$@” start 2>&1 | /usr/sbin/cronolog “$CATALINA_BASE”/logs/catalina.%Y-%m-%d.out >> /dev/null &fi
修改后,重启tomcat
看到更改已经生效 -rw-rw-r– 1 tomcat tomcat 64812 Nov 6 11:03 catalina.2015-11-06.out -rw-rw-r– 1 tomcat tomcat 60161618 Nov 6 11:02 catalina.out转载:http://blog.csdn.net/hanzheng260561728/article/details/51236131