据我所知,我已正确设置logrotate
,但日志根本不会旋转。
我已使用以下配置设置logrotate:
/path/to/logs/my_script.log {
daily
dateext
copytruncate
rotate 400
missingok
compress
}
当我查看日志目录的权限时,我看到:
Thu Jun 9 2016, 09:56:56 AM /path/to/logs
root@my_host $ ls -lath
total 2.0M
-rw-r--r--. 1 qaf qaf 472K Jun 9 09:57 my_script.log
-rw-r--r--. 1 qaf qaf 98 Jun 8 15:50 my_script.logrotate.status
drwxr-xr-x. 3 qaf qaf 108K Jun 8 15:50 .
drwxr-xr-x. 13 qaf qaf 4.0K May 28 22:42 ..
当我使用logrotate -ds
时,它告诉我日志需要旋转。:
Thu Jun 9 2016, 09:57:00 AM /path/to/logs
root@my_host $ logrotate -ds /path/to/logs/my_script.logrotate.status /etc/logrotate.d/my_script.logrotate.conf
reading config file /etc/logrotate.d/my_script.logrotate.conf
reading config info for /path/to/logs/my_script.log
Handling 1 logs
rotating pattern: /path/to/logs/my_script.log after 1 days (400 rotations)
empty log files are rotated, old logs are removed
considering log /path/to/logs/my_script.log
log needs rotating
rotating log /path/to/logs/my_script.log, log->rotateCount is 400
dateext suffix '-20160609'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
copying /path/to/logs/my_script.log to /path/to/logs/my_script.log-20160609
truncating /path/to/logs/my_script.log
compressing log with: /bin/gzip
这是我的/var/lib/logrotate.status
Thu Jun 9 2016, 10:00:13 AM /path/to/logs
root@my_host $ cat /var/lib/logrotate.status
logrotate state -- version 2
"/var/log/yum.log" 2016-1-1
"/var/log/sssd/*.log" 2015-1-29
"/var/log/dracut.log" 2016-1-1
"/var/log/wtmp" 2015-1-29
"/var/log/spooler" 2016-6-5
"/var/log/btmp" 2016-6-1
"/var/log/maillog" 2016-6-5
"/path/to/logs/my_script.log" 2016-6-9
"/var/log/cups/*_log" 2015-1-29
"/var/log/wpa_supplicant.log" 2015-1-29
"/var/log/secure" 2016-6-5
"/var/log/numad.log" 2015-1-29
"/var/log/ppp/connect-errors" 2015-1-29
"/var/log/messages" 2016-6-5
"/var/account/pacct" 2015-1-29
"/var/log/cron" 2016-6-5
答案 0 :(得分:1)
尝试重新启动cron demon和rsyslog
service crond restart
服务rsyslog重启