Tomcat catalina-deamon.out 日志切割 每天生成一个文件
Tomcat 使用 jsvc 以守护进程的方式启动(daemon.sh )。这样tomcat自身将会生成另外一个日志文件(catalina-daemon.out),而不是之前的catalina.out,而且catalina-daemon.out日志不会自动切割,会越来越大。
以前遇到过一个问题,就是网站突然访问空白,排查到最后发现是当前进行了网站打包备份操作,有一个超过2GB的压缩包。删掉后立马页面访问正常。具体原因还不清楚。
同时从运维角度和日志分析角度思考,日志文件最好做切割处理,并日志文件不宜过大。
想了想,还是使用linux的crontab的定时任务吧,
编写一个shell脚本,脚本放到 /etc/cron.daily目录下,代码如下:
#!/bin/bash
thedate=`date --rfc-=date`
predate=`date +%Y-%m-%d --date="-7 day"` rmfile="/xxxx/server/tomcat/logs/catalina-daemon.${predate}.out"
outfile="/xxxx/server/tomcat/logs/catalina-daemon.out"
if [ -f ${rmfile} ];then
rm -f ${rmfile}
fi if [ -f ${outfile} ];then
cp ${outfile} /xxxx/server/tomcat/logs/catalina-daemon.${thedate}.out
echo "" > ${outfile}
fi exit
#!/bin/bash
thedate=`date --rfc-=date`
predate=`date +%Y-%m-%d --date="-7 day"` rmfile1="/xxxxx/server/tomcat/logs/catalina-daemon.${predate}.out"
rmfile2="/xxxxx/server/tomcat/logs/p2p.log.${predate}"
rmfile3="/xxxxx/server/tomcat/logs/localhost.${predate}.log"
rmfile4="/xxxxx/server/tomcat/logs/host-manager.${predate}.log"
rmfile5="/xxxxx/server/tomcat/logs/catalina.${predate}.log"
outfile="/xxxxx/server/tomcat/logs/catalina-daemon.out" for rmfile in "${rmfile1}" "${rmfile2}" "${rmfile3}" "${rmfile4}" "${rmfile5}"
do
if [ -f ${rmfile} ];then
rm -f ${rmfile}
fi
done if [ -f ${outfile} ];then
cp ${outfile} /xxxxx/server/tomcat/logs/catalina-daemon.${thedate}.out
echo "" > ${outfile}
fi exit
检查是否配置好了自动执行配置 ,cat /etc/crontab,没有就加行下文的红色部分。
[root@xxxxServer /]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/ # For details see man crontabs # Example of job definition:
# .---------------- minute ( - )
# | .------------- hour ( - )
# | | .---------- day of month ( - )
# | | | .------- month ( - ) OR jan,feb,mar,apr ...
# | | | | .---- day of week ( - ) (Sunday= or ) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed #run-parts
* * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily //每天执行/etc/cron.daily内的脚本
* * root run-parts /etc/cron.weekly
* * root run-parts /etc/cron.monthly
查看crond服务是否运行:
pgrep crond
或
/sbin/service crond status
或
ps -elf|grep crond|grep -v "grep"
crond服务操作命令:
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
设置crond随机启动
chkconfig crond on
好了,现在就不用担忧日志文件过大问题了!
同时上面的脚本会每天运行一次,并删除七天之前的日志文件,具体时间,可自己设定。
PS:
http://www.cnblogs.com/xd502djj/archive/2010/12/29/1919478.html
http://www.jb51.net/article/34332.htm
http://www.cnblogs.com/panblack/archive/2013/05/30/split_tomcat_catalina_out.html
http://desert3.iteye.com/blog/1393541
Tomcat catalina-deamon.out 日志切割 每天生成一个文件的更多相关文章
- 将String类型的二维数组中的元素用FileOutputStream的write方法生成一个文件
将String类型的二维数组中的元素用FileOutputStream的write方法生成一个文件import java.io.File;import java.io.FileOutputStre ...
- spark中saveAsTextFile如何最终生成一个文件
原文地址: http://www.cnblogs.com/029zz010buct/p/4685173.html 一般而言,saveAsTextFile会按照执行task的多少生成多少个文件,比如pa ...
- Shell 命令行 从日志文件中根据将符合内容的日志输出到另一个文件
Shell 命令行 从日志文件中根据将符合内容的日志输出到另一个文件 前面我写了一篇博文Shell 从日志文件中选择时间段内的日志输出到另一个文件,利用循环实现了我想要实现的内容. 但是用这个脚本的同 ...
- Shell 从日志文件中选择时间段内的日志输出到另一个文件
Shell 从日志文件中选择时间段内的日志输出到另一个文件 情况是这样的,某系统的日志全部写在一个日志文件内,所以这个文件非常大,非常长,每次查阅的时候非常的不方便.所以,相关人员希望能够查询某个时间 ...
- 100个Shell脚本——【脚本8】每日生成一个文件
[脚本8]每日生成一个文件 要求:请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为)2017-07-05.log, 并且把磁盘的使用情况写到到这个文件中,(不用考虑c ...
- tomcat 使用log4j进行日志切割
因为tomcat catalina.out日志不会自己主动切割, 一.日志切割所需包在附近中 1. 压缩包中有三个jar包: log4j-1.2.16.jar tomcat-juli ...
- 配置好Nginx后,通过flume收集日志到hdfs(记得生成本地log时,不要生成一个文件,)
生成本地log最好生成多个文件放在一个文件夹里,特别多的时候一个小时一个文件 配置好Nginx后,通过flume收集日志到hdfs 可参考flume的文件 用flume的案例二 执行的注意点 avro ...
- 使用IO流将数据库中数据生成一个文件,结果使用Notepad++打开部分数据结尾出现NUL
场景描述: 项目中通过java代码中从数据库中查询一系列数据,对数据做相应处理,然后通过字符流将数据写如一个新生成的文件中,将该项目部署在linux服务器上,最后生成的文件拿到本地使用notepad+ ...
- 分割catalina.out 每天生成一个文件
1. touch xxx(文件名字).sh 2. vim xxx.sh 写入 ----------------------- #!/bin/sh cd `dirname $0`pwdd=`d ...
随机推荐
- 【html】param 以及 embed 的有关 flash 属性详解
本文主要介绍 param 和 embed 标签中有关 flash 的一些属性及其属性值. 首先我们需要知道 param 和 embed 标签是单独出现的,而不是成对出现的,下面的代码是一般 flash ...
- Spring Cloud Sleuth 服务跟踪
项目结构: 一跟踪服务中心,用于收集和展示跟踪情况. 一个服务提供者. 一个服务消费者. 服务跟踪中心: pom.xml添加如下依赖: <dependency> <groupId&g ...
- spring框架中的@Import注解
spring框架中的@Import注解 Spring框架中的@Import注解 在之前的文章中,作者介绍了Spring JavaConfig. 这是除了使用传统的XML文件之外,spring带来的新的 ...
- 自然语言交流系统 phxnet团队 创新实训 项目博客 (六)
从你进入软件开始,你就建立了和服务器的联系.这是一段和服务器的长连接,直到你退出此软件. 2D文字聊天界面大致实现了文字输入.发送消息.接收消息.你可以通过点击按钮让机器人开启聊天模式或者学习模式.又 ...
- Entries missing in table T028G T-CODE: OT51 SAP 传输配置操作为用户操作 SAP网银接口
change this setting as a 'current setting' according to SAP note '135028 - Transfer IMG activity to ...
- 【转】JS对Cookie的读写删除
JavaScript是运行在客户端的脚本,因此一般是不能够设置Session的,因为Session是运行在服务器端的.而cookie是运行在客户端的,所以可以用JS来设置cookie. 假设有这样一种 ...
- SpringBoot系列六:SpringBoot整合Tomcat
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合 Tomcat 2.背景 SpringBoot 本身支持有两类的 WEB 容器:默认的 To ...
- Java与编码问题串讲之二–如何理解java采用Unicode编码
Java开发者必须牢记:在Java中字符仅以一种形式存在,那就是Unicode(不选择任何特定的编码,直接使用他们在字符集中的编号,这是统一的唯一方法).由于java采用unicode编码,char ...
- (诊断)处理错误fatal error: Python.h: No such file or directory
安装与Python版本对应的 python-dev 即可,比如: $ -dev
- (原创)OpenStack服务如何使用Keystone (二)---部署和配置Keystone中间件
(一)Keystone端的操作 (二)如何在OpenStack服务上部署Keystone中间件 (三)详细配置keystonemiddleware 部署OpenStack时一般先安装Keystone服 ...