tomcat7catalina.out|tomcat7catalina.out 日志切割及定时清理
一.安装使用cronolog工具对catalina.out日志文件进行切割
#wget http://cronolog.org/download/cronolog-1.6.2.tar.gz2、解压缩
# tar zxvf cronolog-1.6.2.tar.gz3、进入cronolog安装文件所在目录,运行安装
# cd cronolog-1.6.24、查看cronolog安装后所在目录(验证安装是否成功)
# ./configure && make && make install
# which cronolog二.使用cronolog工具对catalina.out日志文件进行切割
/usr/local/sbin/cronolog
进入tomcat/bin目录,打开catalina.sh,修改一下内容
(1)if [ -z "$CATALINA_OUT" ] ; then三,结合sed命令,对多个tomcat进行操作
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
fi
############################################################改为:
if [ -z "$CATALINA_OUT" ] ; then
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out
fi
(2)touch "$CATALINA_OUT"
if [ "$1" = "-security" ] ; then
if [ $have_tty -eq 1 ]; then
echo "Using Security Manager"
fi.......................................
-Djava.io.tmpdir=\"$CATALINA_TMPDIR\" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
else..............................................
【tomcat7catalina.out|tomcat7catalina.out 日志切割及定时清理】-Djava.io.tmpdir=\"$CATALINA_TMPDIR\" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
fi
##############################################改为:
#touch "$CATALINA_OUT"
if [ "$1" = "-security" ] ; then
if [ $have_tty -eq 1 ]; then
echo "Using Security Manager"
................................................
-Djava.io.tmpdir=\"$CATALINA_TMPDIR\" \
org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
| /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &
...........................................
-Djava.io.tmpdir=\"$CATALINA_TMPDIR\" \
org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
| /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &
fi
sed -i 's/touch "$CATALINA_OUT"/#touch "$CATALINA_OUT"/g' catalina.sh
sed -i 's; CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out; CATALINA_OUT="$CATALINA_BASE"/logs/catalina-%Y-%m-%d.out; g' catalina.sh重启tamcat,查看logs目录
-rw-r--r-- 1 root root 2814661 Jan 23 14:25 catalina-2018-01-23.out四.定时清理日志,删除大于十五天的日志,减少磁盘占用
#!/bin/bash添加到定时任务,每天23点10分执行
find /aebiz/soft/jenkins/logs/ -mtime +15 -exec rm {} \;
find /aebiz/soft/jobserver/logs/ -mtime +15 -exec rm {} \;
find /aebiz/soft/recommend/logs/ -mtime +15-exec rm {} \;
find /aebiz/soft/ydyscenter/logs/ -mtime +15-exec rm {} \;
10 23 * * * sh /aebiz/soft/logclean.sh
推荐阅读
- 日志打卡
- Java|规范的打印日志
- 感恩日志20181107
- Java内存泄漏分析系列之二(jstack生成的Thread|Java内存泄漏分析系列之二:jstack生成的Thread Dump日志结构解析)
- 临床统计学学习日志
- 20180322【w4复盘日志】
- Hadoop|Hadoop MapReduce Job提交后的交互日志
- 晨间日志会给你带来什么()
- 20171130W8英语复盘日志
- 人文一班第十二周复盘日志何惠玲