我有/etc/logrotate.d目录填充文件; 每个服务,如httpd,都得到它自己的logrotateconfiguration文件。
/etc/logrotate.d目录中的内容被configuration为在5k后旋转。
我还有一个/etc/logrotate.conf文件,它不在cron中。 它被configuration为:每周轮换日志文件
weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed compress # RPM packages drop log rotation information into this directory include /etc/logrotate.d # no packages own wtmp and btmp -- we'll rotate them here /var/log/wtmp { monthly create 0664 root utmp minsize 1M rotate 1 } /var/log/btmp { monthly create 0664 root utmp minsize 1M rotate 1 }
以下是/etc/logrotate.d/目录中的典型configuration文件:
/var/log/httpd/*log { size 5k missingok notifempty sharedscripts compress sharedscripts postrotate /sbin/service httpd reload > /dev/null 2>/dev/null || true endscript }
我的问题是我必须configuration服务器上的其他位置,以便5k之后的/etc/logrotate.d目录中的文件被旋转。 而且/etc/logrotate.conf被configuration为按照configuration旋转?
这一切对我来说都很好。 你不应该改变任何东西。 一旦logrotate开始执行,事情应该开始像预期的那样旋转。 一个警告是,它可能需要一个完整的旋转周期,事实上开始旋转之前。 有内置的安全措施,以防止太频繁旋转文件。 您可以通过检出logrotate状态文件来监视进程: /var/lib/logrotate.status 。 它包含logrotate正在pipe理的所有文件的列表,以及每个文件上次轮换的时间。
这听起来不错,但要小心,logrotate不是守护进程,日志不会在5k时旋转,但只有在执行logrotate时大小超过5k。 默认情况下,它只能每天运行一次。
从man logrotate :
通常情况下,logrotate是作为日常的cron作业运行的。
logrotate cron文件通常是/etc/cron.daily/logrotate 。 如果您希望logrotate每小时validation一次日志,或者使自定义的cron更频繁地执行它,那么您必须将其移动到/etc/cron.hourly 。
logrotate -d config_file -d Turns on debug mode and implies -v. In debug mode, no changes will be made to the logs or to the logrotate state file.