Linux的logrotate使用
1.进入/etc/logrotate.conf查看配置文件,下面包含了lograte.d文件,具体步骤参照第二步
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}
2.进入/etc/logrotate.d/目录下创建配置文件,格式参照如下(也可在logrotate.conf文件中直接添加)
/home/tomcat/tomcat-dev/logs/catalina.out {
missingok
notifempty
size 20000k
copytruncate
compress
rotate 7
daily
dateext
}
3.进入vim /etc/crontab,新增定时任务的cron表达式
0 0 * * * root run-parts /etc/cron.daily
3.重启项目服务器,定时任务生效