1. 安装cronolog工具
yum install cronolog which cronolog
which cronolog确认安装位置,我的是/usr/sbin/cronolog
2. 修改catalina.sh配置
(1) 370行左右,注释掉
#touch "$CATALINA_OUT"
(2) 383 392行左右
将:
org.apache.catalina.startup.Bootstrap "$@" start \ >> "$CATALINA_OUT" 2>&1 "&"
修改为:
org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \ |/usr/sbin/cronolog "$CATALINA_BASE"/logs/catalina.out.%Y-%m-%d.out>> /dev/null &
3. 重启tomcat即可。
相关编辑位置内容:
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.out.%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.out.%Y-%m-%d.out>> /dev/null &
最后:
如果是copy一份文件,修改后替换文件,注意修改后文件的权限和原先文件一样。
参考文章;
http://www.lxway.net/21105942.html
http://blog.csdn.net/forest_boy/article/details/50115629
来源:oschina
链接:https://my.oschina.net/u/1993939/blog/714305