一、简介
logrotate是个十分有用的工具,它可以自动对日志进行截断(或轮循)、压缩以及删除旧的日志文件。
logrotate配合cron运行。
二、安装
主流Linux发行版上都默认安装有logrotate和cron包,如果没有,可以使用yum install 在线安装。
1 | yum install logrotate cron |
三、配置
logrotate的默认配置文件为/etc/logrotate.conf这相当于是全局配置。
针对具体的应用的配置文件,在这/etc/logrotate.d/
1 2 3 4 5 6 7 8 9 10 11 | [root@qq ~]# ll /etc/logrotate.d/ total 36 -rw-r--r-- 1 root root 71 May 31 2017 cups -rw-r--r-- 1 root root 188 Feb 18 2015 denyhosts -rw-r--r--. 1 root root 139 May 12 2016 dracut -rw-r--r-- 1 root mail 147 Aug 18 23:32 exim -rw-r--r-- 1 root root 172 Jul 12 23:48 iscsiuiolog -rw-r--r-- 1 root root 215 Dec 8 15:45 nginx -rw-r--r-- 1 root root 93 Jun 21 2016 privoxy -rw-r--r--. 1 root root 210 Dec 10 2014 syslog -rw-r--r-- 1 root root 87 Mar 22 2017 yum |
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@qq ~]# cat /etc/logrotate.d/nginx /home/wwwlogs/*log { daily rotate 9999 missingok dateext notifempty nocompress sharedscripts postrotate /usr/local/nginx/sbin/nginx -s reload 2>/dev/null || : endscript } |
四、帮助
1 2 3 4 5 6 7 8 9 10 11 | # logrotate --help Usage: logrotate [OPTION...] <configfile> -d, --debug Don't do anything, just test (implies -v) -f, --force Force file rotation -m, --mail=command Command to send mail (instead of `/bin/mail') -s, --state=statefile Path of state file -v, --verbose Display messages during rotation Help options: -?, --help Show this help message --usage Display brief usage message |
会员登录关闭
注册会员关闭