我刚刚build立一个(R)系统日志服务器来接收各种客户端的日志,这工作正常。
只有logrotate仍然没有performance的意图。 我想logrotate为每一天创build一个新的日志文件,但只保留和存储即压缩非空文件。
我的logrotateconfiguration看起来像这样
# sample configuration for logrotate being a remote server for multiple clients /var/log/syslog { rotate 3 daily missingok notifempty delaycompress compress dateext nomail postrotate reload rsyslog >/dev/null 2>&1 || true endscript } # local ie the system's very own logs: keep logs for a whole month /var/log/kern.log /var/log/kernel-info /var/log/auth.log /var/log/auth-info /var/log/cron.log /var/log/cron-info /var/log/daemon.log /var/log/daemon-info /var/log/mail.log /var/log/rsyslog /var/log/rsyslog-info { rotate 31 daily missingok notifempty delaycompress compress dateext nomail sharedscripts postrotate reload rsyslog >/dev/null 2>&1 || true endscript } # received ie logs from the clients /var/log/path-to-logs/*/* { rotate 31 daily missingok notifempty delaycompress compress dateext nomail }
我最终得到的是一些“汇总”的文件,如文件名datestampDay天和相应的.gz文件。 我所做的是空文件,最终压缩。
那么notifempty指令实际上是负责这些DayX-DayY文件的,那几天真的什么都没有发生?
什么将是一个有效的方式来删除这两个空的日志文件和他们的.gz文件,以便我最终只保留真正包含数据的日志/压缩文件?
Notifempty正常工作,从您的configuration中删除delaycompress。
我已经在本地计算机上testing过了,它应该按照你想要的方式工作。
这也是一个好的命令:
logrotate -d /etc/logrotate.d/<CONFIG_FILE>
它会告诉你如何处理日志而不进行实际的日志处理。