使用cronolog工具切分Tomcat的catalina.out日志文件
普通用户下载、安装cronolog
[tomcat@localhost ~]$ tar -xf cronolog-1.6.2.tar.gz
[tomcat@localhost ~]$ cd cronolog-1.6.2/
[tomcat@localhost cronolog-1.6.2]$ ./configure --prefix=/home/tomcat/cronolog
make
make install
root用户下下载、安装cronolog
[root@localhost ~]# rpm -qa |grep cronolog
[root@localhost ~]# tar zxvf cronolog-1.6.2.tar.gz
[root@localhost ~]# cd cronolog-1.6.2
[root@localhost cronolog-1.6.2]# ./configure
[root@localhost cronolog-1.6.2]# make && make install
[root@localhost cronolog-1.6.2]# which cronolog
/usr/local/sbin/cronolog
在普通用户的家目录下编辑.bash_profile文件里添加“$HOME/cronolog/sbin”添加cronolog的安装路径
[tomcat@localhost ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:$HOME/cronolog/sbin
export PATH
用which cronolog可以查到安装的路径,这个路径待会在修改catalina.sh时会用到。
修改catalina.sh 文件
将186行【CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out】修改成187行【CATALINA_OUT="$CATALINA_BASE"/logs/opres.%Y-%m-%d.out】内容,日志名可以自行定义;
注释掉370行【touch "$CATALINA_OUT"】;
383、384行【
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"】替换成385、386行【
org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
| /home/tomcat/cronolog/sbin/cronolog "$CATALINA_OUT" >> /dev/null 2>&1 &
】;
396、397行【
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
】替换成394、395行【
org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
| /home/tomcat/cronolog/sbin/cronolog "$CATALINA_OUT" >> /dev/null 2>&1 &
】;最后一步(394、395)要注意如果原本的命令只是注释掉,替换的内容一定要在原本内容的上面,不然无法正常启动,前面的替换(383、384)位置没有关系的
97 Java_OPTS="-Xms512m -Xmx1024m -Xss1024K -XX:PermSize=256m -XX:MaxPermSize=512m"
98
99 # OS specific support. $var _must_ be set to either true or false.
185 if [ -z "$CATALINA_OUT" ] ; then
186 # CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
187 CATALINA_OUT="$CATALINA_BASE"/logs/opres.%Y-%m-%d.out
370 #touch "$CATALINA_OUT"
371 if [ "$1" = "-security" ] ; then
372 if [ $have_tty -eq 1 ]; then
373 echo "Using Security Manager"
374 fi
375 shift
376 eval "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
377 -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
378 -Djava.security.manager \
379 -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
380 -Dcatalina.base="\"$CATALINA_BASE\"" \
381 -Dcatalina.home="\"$CATALINA_HOME\"" \
382 -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
383 # org.apache.catalina.startup.Bootstrap "$@" start \
384 # >> "$CATALINA_OUT" 2>&1 "&"
385 org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
386 | /home/tomcat/cronolog/sbin/cronolog "$CATALINA_OUT" >> /dev/null 2>&1 &
387
388 else
389 eval "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
390 -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
391 -Dcatalina.base="\"$CATALINA_BASE\"" \
392 -Dcatalina.home="\"$CATALINA_HOME\"" \
393 -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
394 org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
395 | /home/tomcat/cronolog/sbin/cronolog "$CATALINA_OUT" >> /dev/null 2>&1 &
396 # org.apache.catalina.startup.Bootstrap "$@" start \
397 # >> "$CATALINA_OUT" 2>&1 "&"
398 fi