cronolog 分割tomcat catalina.out日志

转载链接--http://blog.chinaunix.net/uid-29680017-id-5757824.html

由于公司运行的tomcat下catalina.out越来越大,所以怕以后对系统有影响,所以采用cronolog来将catalina.out每天生成一份

1.下载cronolog-1.6.2.tar.gz
官网打不开,但是在CU上找到了
http://download.chinaunix.net/download.php?id=3457&ResourceID=1851
2.安装cronolog
tar -zxf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure --prefix=/home/xxxx/cronolog(因为是非root用户,所以解压到用户home下,如果是root可不加此参数) 
make && make install
3.修改catalina.sh(此文件在tomca目录下bin文件夹)
需要修改3处:
1)将:
if [ -z "$CATALINA_OUT" ] ; then
  CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
fi
改为:
if [ -z "$CATALINA_OUT" ] ; then
  CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out.%Y-%m-%d
fi

2)注释 touch "$CATALINA_OUT",约370行
# touch "$CATALINA_OUT"

3)将:
 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

改为:
 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 |/home/xxx/cronolog/sbin/cronolog "$CATALINA_OUT" &        #(注意cronolog实际安装路径)

 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 |/home/xxx/cronolog/sbin/cronolog "$CATALINA_OUT" &        #(注意cronolog实际安装路径)

 fi
最后,重启tomcat即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值