logrotate 控制 tomcat日志

1、例子:

[root@VM etc]# cat /etc/logrotate.d/tomcat
/opt/apache-tomcat-6.0.26/logs/catalina.out {
daily
dateext
rotate 10
missingok
notifempty
copytruncate

}

2、配置说明:

daily:日志文件每天进行滚动

rotate:保留最5次滚动的日志

notifempty:日志文件为空不进行滚动

dateext 每天执行一次,同时转储旧日志时用日期格式"YYMMDD"代替简单的数字作为标记

sharedscripts:运行postrotate脚本

postrotate :开始脚本

endscript:结束脚本


3.配置生效

 /usr/sbin/logrotate /etc/logrotate.conf 


4.测试执行

   logrotate /etc/logrotate.d/log-file


5.修改执行时间 vi  /etc/anacrontab 

在 CentOS 是使用 anacron 來設定 logrotate 執行的時段,可修改 /etc/anacrontab 裡面 START_HOURS_RANGE 的設定

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
#START_HOURS_RANGE=3-22
#改成早上 3~5 點的時候執行
START_HOURS_RANGE=3-5

#period in days   delay in minutes   job-identifier   command
1       5       cron.daily              nice run-parts /etc/cron.daily
7       25      cron.weekly             nice run-parts /etc/cron.weekly
@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值