Linux-logrotate

Using the logrotate command allows you to easily manage the log files generated by the system. It provides automatic replacement, compression, deletion and mailing of log files. Each log file can be set to be processed daily, weekly or monthly. It can also be processed immediately when the file is too large. You must edit it yourself and specify the configuration file. The default configuration file is stored in the / etc directory and the file name is logrotate.conf.

#yum install logrotate crontabs
logrotate的配置文件是/etc/logrotate.conf
日志文件的轮循设置在独立的配置文件中,在/etc/logrotate.d/目录下。
eg
vim /etc/logrotate.d/log-file
/var/log/log-file {
monthly
rotate 5
compress
delaycompress
missingok
notifempty
create 644 root root
postrotate
/usr/bin/killall -HUP rsyslogd
end
}
compress 通过gzip 压缩转储以后的日志
nocompress 不需要压缩时,用这个参数
copytruncate 用于还在打开中的日志文件,把当前日志备份并截断
nocopytruncate 备份日志文件但是不截断
create mode owner group 转储文件,使用指定的文件模式创建新的日志文件
nocreate 不建立新的日志文件
delaycompress 和 compress 一起使用时,转储的日志文件到下一次转储时才压缩
nodelaycompress 覆盖 delaycompress 选项,转储同时压缩。
errors address 专储时的错误信息发送到指定的Email 地址
ifempty 即使是空文件也转储,这个是 logrotate 的缺省选项。
notifempty 如果是空文件的话,不转储
mail address 把转储的日志文件发送到指定的E-mail 地址
nomail 转储时不发送日志文件
olddir directory 转储后的日志文件放入指定的目录,必须和当前日志文件在同一个文件系统
noolddir 转储后的日志文件和当前日志文件放在同一个目录下
prerotate/endscript 在转储以前需要执行的命令可以放入这个对,这两个关键字必须单独成行
postrotate/endscript 在转储以后需要执行的命令可以放入这个对,这两个关键字必须单独成行
daily 指定转储周期为每天
weekly 指定转储周期为每周
monthly 指定转储周期为每月
rotate count 指定日志文件删除之前转储的次数,0 指没有备份,5 指保留5 个备份
tabootext [+] list 让logrotate 不转储指定扩展名的文件,缺省的扩展名是:.rpm-orig, .rpmsave, v, 和 ~
size size 当日志文件到达指定的大小时才转储,Size 可以指定 bytes (缺省)以及K (sizek)或者M (sizem).
dateext   ; 为日志文件打上日期标签
强制执行
logrotate -vf /etc/logrotate.d/log-file
-d 选项以预演方式运行logrotate
-f 选项来强制logrotate轮循日志文件
-v 参数提供了详细的输出
日志记录
logrotate自身的日志通常存放于/var/lib/logrotate/status目录。如果处于排障目的,我们想要logrotate记录到任何指定的文件,我们可以指定像下面这样从命令行指定。
# logrotate -vf –s /var/log/logrotate-status /etc/logrotate.d/log-file
Logrotate定时任务
logrotate需要的cron任务应该在安装时就自动创建了
#cat /etc/cron.daily/logrotate

Published 52 original articles · won praise 2 · Views 6374

Guess you like

Origin blog.csdn.net/wenwang3000/article/details/99644640