logrotate 日志分割
参考地址: https://linux.cn/article-4126-1.html
参考地址: http://blog.csdn.net/wanglipo/article/details/6934926
vim /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly
# 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 99
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 99
}
# system-specific logs may be also be configured here.
vim /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 nginx adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
vim /etc/logrotate.d/tomcat
/data/chexian-manage/logs/*.log{
rotate 15
daily
copytruncate
compress
notifempty
missingok
}
其中:
rotate 7 表示保留7天的备份文件
daily 表示每天整理一次
copytruncate 表示先复制log文件的内容,然后再清空
compress 表示压缩备分文件
missingok 表示如果找不到log文件也没OK
notifempty 表示如果log文件是空的,就不进行rotate
网友评论