tomcat7使用conologs把catalina.out日志按日切割

安装cronolog

下载好安装包(https://files.cnblogs.com/files/crazyzero/cronolog-1.6.2.tar.gz)

# wget  https://files.cnblogs.com/files/crazyzero/cronolog-1.6.2.tar.gz

# ll cronolog-1.6.2.tar.gz 

 

解压并进入

# tar xf cronolog-1.6.2.tar.gz 
# cd cronolog-1.6.2

 

编译安装

# ./configure 
# make
# make install 

 

生成cronolog工具

# ll /usr/local/sbin/cronolog 

 

修改配置文件 tomcat/bin/catalina.sh  共四处

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.%Y-%m-%d.out
fi

 

2.

touch "$CATALINA_OUT" 

修改为

#touch "$CATALINA_OUT"


3和4

org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
| /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &

共有两处 改为下面的即可

org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \ |/usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.out.%Y-%m-%d.out>> /dev/null &
 

遇到的坑:我换换行打了空格,启动时shell命令不认为他是一命令了。所以3和4都是两行改为一行

发表评论:

共有 0 条评论

 Top