本文主要講述使用cronolog分割tomcat的catalina.out文件。java
wget https://files-cdn.cnblogs.com/files/shidian/cronolog-1.6.2.tar.gz tar zxvf cronolog-1.6.2.tar.gz cd cronolog-1.6.2./configure make make install
which cronolog 通常狀況下顯示爲:/usr/local/sbin/cronolog
以下圖所示:apache
找到下面這個,相似這樣的行有2處:tomcat
org.apache.catalina.startup.Bootstrap "$@" start \ >> "$CATALINA_OUT" 2>&1 "&"
第一處:Tomcat是帶"-security"參數的啓動。spa
第二處:默認Tomcat啓動方式,也就是else下面那部分,咱們只修改這裏。日誌
另外還要把touch "$CATALINA_OUT"這樣註釋掉。code
修改後的結果以下所示:cdn
# touch "$CATALINA_OUT" if [ "$1" = "-security" ] ; then if [ $have_tty -eq 1 ]; then echo "Using Security Manager" fi shift eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -D$ENDORSED_PROP="\"$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 $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ # -D$ENDORSED_PROP="\"$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 "&" "$_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/local/sbin/cronolog /opt/tomcat/apache-tomcat-9.0.13/logs/catalina.%Y%m%d.out >> /dev/null & fi
將原來else的腳本屏蔽掉,加入後面的這段代碼。blog
重啓後logs目錄以下所示:get
配置cronolog完成了,觀察天天是否有個新的catalina.yymmdd.out的日誌文件生成,按期刪除日期較舊的日誌文件。it
【參考資料】