Cronolog切割tomcat日志

Cronolog切割tomcat

安装cronolog

1、 cronolog-1.6.2.tar.gz 上传至/opt 目录

2、 解压缩

#解压缩

tar -zxvf cronolog-1.6.2.tar.gz

#修改文件夹

mv cronolog-1.6.2/ cronolog

3、 安装

#进入cronolog目录

    cd cronolog/

./configure

make

make install

4、 检验是否安装完成

which cronolog

#一般情况下显示为:/usr/local/sbin/cronolog 

修改配置文件(或者直接替换)

1、 停止tomcat

2、 进入tomcat/bin 目录

cd /usr/local/tomcat6/bin/

3、 修改配置文件

vi catalina.sh

# 注释掉355

touch "$CATALINA_OUT"  修改为  #touch "$CATALINA_OUT"

#修改 368369

org.apache.catalina.startup.Bootstrap "$@" start \

>> "$CATALINA_OUT" 2>&1 &

修改为

org.apache.catalina.startup.Bootstrap "$@" start  2>&1 \

| /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d_%H.out >> /dev/null &

#修改 377378

org.apache.catalina.startup.Bootstrap "$@" start \

>> "$CATALINA_OUT" 2>&1 &

修改为

org.apache.catalina.startup.Bootstrap "$@" start  2>&1 \

| /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d_%H.out >> /dev/null &

 

4、 重启tomcat

###############################################################################

替换文件:

附件中的catalina.sh 为已修改过的。将改文件直接替换即可。(需要比较该文件替换前后的执行权限。)

 

tomcat8.5可能显示不太一样:

建议将第453-491的代码shift
  if [ -z "$CATALINA_OUT_CMD" ] ; then
    touch "$CATALINA_OUT"
    catalina_out_command=">> \"$CATALINA_OUT\" 2>&1"
  else
    catalina_out_command="| $CATALINA_OUT_CMD"
  fi
  if [ ! -z "$CATALINA_PID" ]; then
    catalina_pid_file="$CATALINA_PID"
  else
    catalina_pid_file=/dev/null
  fi
  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 \
      2\>\&1 \&\& echo \$! \>\"$catalina_pid_file\" \; \} $catalina_out_command "&"

  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 \
      2\>\&1 \&\& echo \$! \>\"$catalina_pid_file\" \; \} $catalina_out_command "&"

  fi

直接替换为

shift
  #touch "$CATALINA_OUT"
  if [ "$1" = "-security" ] ; then
    if [ $have_tty -eq 1 ]; then
      echo "Using Security Manager"
    fi
    shift
    "$_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/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d_%H.out >> /dev/null &

  else
    "$_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 "$CATALINA_BASE"/logs/catalina.%Y-%m-%d_%H.out >> /dev/null &

  fi

posted @ 2019-03-13 10:41  宝贝企鹅  阅读(1319)  评论(1编辑  收藏  举报