1、linux 自带的 logrotate 命令
2、定义切割文件相关信息
那个目录下的什么文件,例如把/var/log/nginx/*.log 已.log结尾的文件压缩打包
在/var/logrotate下创建一个 nginx 的文件,内容如下:
/var/log/nginx/*.log {
daily #按天打包
rotate 180 #保存周期为180以内的,超过180天的则删除
missingok
notifempty
dateext
compress
nodelaycompress
sharedscripts
postrotate
/etc/init.d/nginx reload
endscript
}
3、crontab 设置一个定时任务
每天晚上23点59分,切割打包日志文件
59 23 * * * /usr/sbin/logrotate -f /var/logrotate/nginx >> /tmp/logrotate.log
网友评论