![Ubuntu 12.04 中的 Squid3 logrotate 错误](https://linux22.com/image/628668/Ubuntu%2012.04%20%E4%B8%AD%E7%9A%84%20Squid3%20logrotate%20%E9%94%99%E8%AF%AF.png)
在 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
知道这里可以检查什么吗?谢谢。
答案1
正如日志条目所示,脚本存在错误prerotate
。
为了调试这个问题,可以从配置中删除脚本,然后逐个添加回来,直到找到有问题的脚本。
也可以手动执行它们以查看哪一个失败,但在这种情况下,OP 说它们默默失败了。
使用logrotate -vf /etc/logrotate.d/squid3
(-v 表示 vervose,-f 表示 force)是另一种选择,在这种情况下有助于获取有关问题的数据。
关于 logrotate 的良好文档可以在这里找到: