logrotate是一个日志文件管理工具。用来把旧文件轮转、压缩、删除,并且创建新的日志文件。我们可以根据日志文件的大小、天数等来转储,便于对日志文件管理,一般都是通过cron计划任务来完成的。
1. 配置实例
/var/log/messages {
rotate 5
weekly
postrotate
/sbin/killall -HUP syslogd
endscript
}
"/var/log/httpd/access.log" /var/log/httpd/error.log {
rotate 5
mail [email protected]
size 100k
sharedscripts
postrotate
/sbin/killall -HUP httpd
endscript
}
/var/log/news/* {
monthly
rotate 2
olddir /var/log/news/old
missingok
postrotate
kill -HUP ‘cat /var/run/inn.pid‘
endscript
nocompress
}
Usage: logrotate [OPTION...] <configfile>
-d, --debug 调试模式,输出调试结果,并不执行。隐式-v参数
-f, --force 强制模式,对所有相关文件进行rotate
-m, --mail=command 发送邮件 (instead of `/bin/mail')
-s, --state=statefile 状态文件,对于运行在不同用户情况下有用
-v, --verbose 显示debug信息