日志回滚管理 |
Logrotate是基于CRON来运行的,其脚本是/etc/cron.daily/logrotate,日志轮转是系统自动完成的。 实际运行时,Logrotate会调用配置文件/etc/logrotate.conf。 可以在/etc/logrotate.d目录里放置自定义好的配置文件,用来覆盖Logrotate的缺省值。
加载流程:
1cat /etc/cron.daily/logrotate
2#脚本是/etc/cron.daily/logrotate
3
4/usr/sbin/logrotate /etc/logrotate.conf
5EXITVALUE=$?
6if [ $EXITVALUE != 0 ]; then
7/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
8fi
9exit 0
如果等不及cron自动执行日志轮转,想手动强制切割日志,需要加-f参数;不过正式执行前最好通过Debug选项来验证一下(-d参数),这对调试也很重要
xxxxxxxxxx
101logrotate /etc/logrotate.conf #加载指定的配置文件。
2/usr/sbin/logrotate -f /etc/logrotate.d/nginx #强制立刻切割。
3/usr/sbin/logrotate -d -f /etc/logrotate.d/nginx #强制但只调试验证
4
5logrotate命令格式:
6logrotate [OPTION...] <configfile>
7-d, --debug :debug模式,测试配置文件是否有错误。
8-f, --force :强制转储文件。
9-m, --mail=command :压缩日志后,发送日志到指定邮箱。
10-s, --state=statefile :使用指定的状态文件。
系统中其它示例参考
xxxxxxxxxx
91cat /etc/logrotate.d/program
2#配置内容
3/var/log/wtmp {
4 monthly
5 create 0664 root utmp
6 minsize 1M
7 compress
8 rotate 1
9}
附录引用 |
无