我已经设置了一个带有一些过滤器的 Syslog-ng 服务器,以将某些流量分成不同的文件。我修改了位于 的 logrotate 文件/etc/logrotate.d/syslog-ng以每天轮换这些文件,但 logrotate 没有按预期运行。我必须手动旋转日志sudo logrotate -f /etc/logrotate.d/syslog-ng
我找不到它不自动运行的原因。
/etc/logrotate.d/syslog-ng 文件的内容(我添加的部分是最顶部的块):
/var/log/wlc /var/log/userid /var/log/cltolt040 /var/log/ise /var/log/vg /var/log/firewall /var/log/steelhead /var/log/syslog /var/log/f5 /var/log/switch /var/log/router
{
su root root
rotate 14
create 0755 ics ics
daily
missingok
notifempty
compress
postrotate
invoke-rc.d syslog-ng reload > /dev/null
endscript
}
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
/var/log/error
{
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d syslog-ng reload > /dev/null
endscript
}
Run Code Online (Sandbox Code Playgroud)
crontab 的内容:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Run Code Online (Sandbox Code Playgroud)
/etc/cron.daily/logrotate 的内容:
#!/bin/sh
# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
[ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
Run Code Online (Sandbox Code Playgroud)
我在想这可能是权限问题,但如果是这种情况,运行 logrotate -f 不会也失败吗?
看起来我已经解决了这个问题。我试图在 conf 文件而不是 syslog-ng 文件上运行 logrotate,logrotate -d /etc/logrotate.conf但它抛出了这个错误Ignoring /etc/logrotate.conf because of bad file mode. 做了一个快速搜索,发现这可能是因为文件权限。我更改了文件的权限sudo chmod 644 /etc/logrotate.conf并通过更改 /etc/crontab 中的每日时间来运行测试。
然后文件自动旋转。所以看起来这是修复。谢谢您的帮助。