##配置html
/usr/local/nginx/logs/*.log { daily dateext rotate 1 olddir /usr/local/nginx/other/logs missingok notifempty compress sharedscripts postrotate /bin/kill -USR1 $(cat /var/run/nginx.pid 2>/dev/null) 2>/dev/null ||: endscript }
dateext
:文件后缀是日期格式,也就是切割后文件是:xxx.log-20150529(.gz) 这样,若是注释掉,切割出来是按数字递增,即前面说的 xxx.log-1(.gz)monthly
: 日志文件将按月轮循。其它可用值为‘daily’,‘weekly’或者‘yearly’。rotate n
: 一次将存储n
个归档日志。对于第n=1
个归档,时间最久的归档将被删除。compress
: 在轮循任务完成后,已轮循的归档将使用gzip
进行压缩。相反的命令是nocompress
delaycompress
: 老是与compress
选项一块儿用,delaycompress
选项指示logrotate不要将最近的归档压缩,压缩将在下一次轮循周期进行。missingok
: 在日志轮循期间,任何错误将被忽略,例如“文件没法找到”之类的错误。notifempty
: 若是日志文件为空,轮循不会进行。相反命令ifempty
是缺省值prerotate/endscript
:在转储之前须要执行的命令能够放入这个对,这两个关键字必须单独成行postrotate/endscript
:在转储之后须要执行的命令能够放入这个对,这两个关键字必须单独成行sharedscripts
:全部的日志文件都轮转完毕后统一执行一次脚本olddir
转储后的日志文件放入指定的目录,必须和当前日志文件在同一个文件系统##操做 路径/etc/logrotate.conf
为默认的配置路径,配置特定的日志处理,通常放在/etc/logrotate.d/
下。在logrotate.conf
中 使用include path
包含对应路径linux
要调用为/etc/lograte.d/
下配置的全部日志调用logrotate
:nginx
logrotate /etc/logrotate.conf
要为某个特定的配置调用logrotate
工具
logrotate /etc/logrotate.d/log-file
排障过程当中的最佳选择是使用-d
选项以预演方式运行logrotate
。要进行验证,不用实际轮循任何日志文件,能够模拟演练日志轮循并显示其输出。post
logrotate -d /etc/logrotate.d/log-file
即便轮循条件没有知足,咱们也能够经过使用-f
选项来强制logrotate轮循日志文件,-v
参数提供了详细的输出。日志
logrotate -vf /etc/logrotate.d/log-file
参考文档:code