/etc/logrotate.d
实现nginx日志文件定时切割处理
日志切割方法一: 利用脚本实现切割
#!/bin/bash
mv /var/log/nginx/access.log /var/log/nginx/access_$(date +%F).log
systemctl restart nginx
日志切割方法二: 利用专用文件切割程序--logrotate
vim /etc/logrotate.conf
# 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 --- 加载包含/etc/logrotate.d/目录中文件配置
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp { --- 单独对某个文件进行切割配置
monthly
create 0664 root utmp
minsize 1M --- 最小大小为1M,小于1M不进行切割
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}
06-27
1345
04-29
1764
08-06
1039