安装cronolog
#公网下载
wget https://files.cnblogs.com/files/crazyzero/cronolog-1.6.2.tar.gz
#公司内网下载
wget http://10.130.36.117/Deploymentpackage/cronolog-1.6.2.tar.gz
[root@ucloud_nginx_1 ~]# tar xvf cronolog-1.6.2.tar.gz ; cd cronolog-1.6.2
[root@ucloud_nginx_1 cronolog-1.6.2]# ./configure ;make -j 2 && make install
#查看二进制路径
[root@ucloud_nginx_1 cronolog-1.6.2]# which cronolog
/usr/local/sbin/cronolog
- 首先配置原有catalina.sh启动脚本,并进行修改
[portal@ucloud_nginx_1 ~]$ cd ~/apache-tomcat-7.0.86/bin;
[portal@ucloud_nginx_1 bin]$ cp catalina.sh catalina.sh_`date +%F`
[portal@ucloud_nginx_1 bin]$ sed -i 's/touch "$CATALINA_OUT"/#touch "$CATALINA_OUT"/g' catalina.sh
[portal@ucloud_nginx_1 bin]$ sed -i 's/org.apache.catalina.startup.Bootstrap "$@" start \/org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \/g'
把配置文件以下两行进行修改:
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
修改如下:
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 \ #改行进行修改
| /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null & #改行进行修改
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 \ #改行进行修改
| /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null & #改行进行修改
fi
重启tomcat服务,并观察catalina.out 是否已按日志区分
评论区