我有此日志详细信息配置:
/opt/freeradius/logs/*/detail {
daily
rotate 4
compress
delaycompress
missingok
notifempty
create 0640 root root
sharedscripts
maxsize 500M
postrotate
/bin/systemctl reload freeradius > /dev/null 2>/dev/null || true
endscript
}
我有这些旧日志和新日志:
[root@freeradius01 192.168.17.10]# pwd
/opt/freeradius/logs/192.168.17.10
[root@freeradius01 192.168.17.10]# ll
total 56919724
-rwxrwxrwx 1 root root 21048752215 Aug 14 23:59 detail-20240814
-rwxrwxrwx 1 root root 21617187765 Aug 15 23:59 detail-20240815
-rwxrwxrwx 1 root root 5988044800 Aug 16 23:59 detail-20240816
-rwxrwxrwx 1 root root 5947392 Sep 25 23:59 detail-20240925
-rwxrwxrwx 1 root root 7478423552 Oct 21 23:59 detail-20241021
-rwxrwxrwx 1 root root 1907452140 Oct 22 11:19 detail-20241022
[root@freeradius01 192.168.17.10]#
当手动运行 logrotate 并强制使用 verbos 时,我得到以下结果:
[root@freeradius01 192.168.17.10]# /usr/sbin/logrotate -v -f /etc/logrotate.d/radiusd
reading config file /etc/logrotate.d/radiusd
Reading state from file: /var/lib/logrotate/logrotate.status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
..
..
Creating new state
Handling logs
rotating pattern: /opt/freeradius/logs/*/detail forced from command line (4 rotations)
empty log files are not rotated, log files >= 524288000 are rotated earlier, old logs are removed
considering log /opt/freeradius/logs/*/detail
not running postrotate script, since no logs were rotated
[root@freeradius01 192.168.17.10]# ll
total 56919724
-rwxrwxrwx 1 root root 21048752215 Aug 14 23:59 detail-20240814
-rwxrwxrwx 1 root root 21617187765 Aug 15 23:59 detail-20240815
-rwxrwxrwx 1 root root 5988044800 Aug 16 23:59 detail-20240816
-rwxrwxrwx 1 root root 5947392 Sep 25 23:59 detail-20240925
-rwxrwxrwx 1 root root 7478423552 Oct 21 23:59 detail-20241021
-rwxrwxrwx 1 root root 1968389637 Oct 22 11:22 detail-20241022
[root@freeradius01 192.168.17.10]# grep "detail" /var/lib/logrotate/logrotate.status
"/var/log/radius/radacct/*/detail" 2024-3-5-3:0:0
"/opt/freeradius/logs/*/detail" 2024-3-5-3:0:0
[root@freeradius01 192.168.17.10]# date
Tue Oct 22 11:22:45 WAT 2024
[root@freeradius01 192.168.17.10]#
因此,尽管我手动运行了日志轮换,但它并没有运行/而且旧日志也没有压缩!!?
当规则的模式与
/opt/freeradius/logs/*/detail
目录中的任何日志文件都不匹配时,logrotate
则不执行任何操作。在这种情况下,您需要detail
在目录中创建一个虚拟文件,/opt/freeradius/logs/192.168.17.10/
然后尝试强制执行 logrotate。但您还需要notifempty
从配置中暂时删除,并且不要在与已经存在的日期扩展相同的日期执行此操作-20241022
,否则 logrotate 将中止,因为文件已经存在。