在 Ubuntu 12.04 服务器中,Squid3 的 logrotate 不起作用。当我注意到分区已从 squid3 日志中填满时,我发现了问题。强制 logrotate 会产生以下错误:
~# logrotate -f /etc/logrotate.d/squid3
error: error running shared prerotate script for '/var/log/squid3/*.log
这是完整的调试输出:
~# logrotate -f /etc/logrotate.d/squid3 -d
reading config file /etc/logrotate.d/squid3
reading config info for /var/log/squid3/*.log
Handling 1 logs
rotating pattern: /var/log/squid3/*.log forced from command line (2 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/squid3/access.log
log needs rotating
considering log /var/log/squid3/cache.log
log needs rotating
rotating log /var/log/squid3/access.log, log->rotateCount is 2
dateext suffix '-20140312'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /var/log/squid3/access.log.1 does not exist
renaming /var/log/squid3/access.log.2.gz to /var/log/squid3/access.log.3.gz (rotatecount 2, logstart 1, i 2),
renaming /var/log/squid3/access.log.1.gz to /var/log/squid3/access.log.2.gz (rotatecount 2, logstart 1, i 1),
renaming /var/log/squid3/access.log.0.gz to /var/log/squid3/access.log.1.gz (rotatecount 2, logstart 1, i 0),
rotating log /var/log/squid3/cache.log, log->rotateCount is 2
dateext suffix '-20140312'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /var/log/squid3/cache.log.1 does not exist
renaming /var/log/squid3/cache.log.2.gz to /var/log/squid3/cache.log.3.gz (rotatecount 2, logstart 1, i 2),
renaming /var/log/squid3/cache.log.1.gz to /var/log/squid3/cache.log.2.gz (rotatecount 2, logstart 1, i 1),
renaming /var/log/squid3/cache.log.0.gz to /var/log/squid3/cache.log.1.gz (rotatecount 2, logstart 1, i 0),
running prerotate script
running script (multiple) with arg /var/log/squid3/*.log : "
test ! -x /usr/sbin/sarg-reports || /usr/sbin/sarg-reports
"
renaming /var/log/squid3/access.log to /var/log/squid3/access.log.1
renaming /var/log/squid3/cache.log to /var/log/squid3/cache.log.1
running postrotate script
running script (multiple) with arg /var/log/squid3/*.log : "
test ! -e /var/run/squid3.pid || /usr/sbin/squid3 -k rotate
"
removing old log /var/log/squid3/access.log.3.gz
error: error opening /var/log/squid3/access.log.3.gz: file or directory not found
知道可以在这里检查什么吗?谢谢。
prerotate
如日志条目所示,脚本存在错误。要调试这一点,可以从配置中删除脚本,然后将它们一一添加,直到找到麻烦的脚本。
它们也可以手动执行以查看哪个失败,但在这种情况下,OP 说它们默默地失败了。
使用
logrotate -vf /etc/logrotate.d/squid3
(-v for vervose,-f for force)是另一种选择,在这种情况下有助于获取有关问题的数据。可以在此处找到有关 logrotate 的良好文档: