Logrotate 不压缩

Logrotate 不压缩

var/log/remots/*/*我需要使用以下 logrotate 规则压缩文件

/var/log/remots/*/* {
    rotate 178
    daily
    maxage 178
    compress
}

位于/etc/logrotate.d/remots

我也写了脚本,看起来像这样。

cp rsyslog.conf /etc/rsyslog.conf
cp 10-remot.conf /etc/rsyslog.d/10-remot.conf
cp remots /etc/logrotate.d/remots

./rpgp.sh perms.txt

service rsyslog restart

但是,当我强制 logrotate 时,sudo logrotate -­d ­­--force /etc/logrotate.d/remots日志仍为纯文本,未压缩。输出类似于很多消息,例如

renaming /var/log/remots/GSX/2019-03-25.2.gz to /var/log/remots/GSX/2019-03-25.3.gz (rotatecount 178, logstart 1, i 2)
renaming /var/log/remots/GSX/2019-03-25.1.gz to /var/log/remots/GSX/2019-03-25.2.gz (rotatecount 178, logstart 1, i 1),
renaming /var/log/remots/GSX/2019-03-25.0.gz to /var/log/remots/GSX/2019-03-25.1.gz (rotatecount 178, logstart 1, i 0),

最后

/var/log/remots/GSX/2019-03-25.179.gz doesnt' exist -- wont't you try to dispose of it
renaming /var/log/remots/GSX/2019-03-25 to /var/log/remots/GSX(2019-03-25.1
compressing log with: /bin/gzip

PD:10-remots.conf 看起来像

$template GuardaRemots, "/var/log/remots/%HOSTNAME%/%timegenerated:1:10:date-rfc3339%"
:source, !isequal, "localhost" -? GuardaRemots

rsyslog.conf 只是配置为通过 UDP 端口 514 进行侦听

答案1

据我所见,logrotate 越来越混乱。首先,您应该对您的名称模式更加严格。/var/log/remots/*/*你应该旋转而不是旋转:

/var/log/remots/*/*.log {
    rotate 178
    daily
    maxage 178
    compress
}

当您更改配置时,请记住检查/var/lib/logrotate/status.删除文件的所有条目.*gz


将 logrotate 与轮换自己的日志的程序混合使用的情况不太常见。您已将 rsyslog 配置为写入过时的日志文件。更常见的是使用静态文件名并允许 logrotate 为您附加日期。我注意到其他人在使用相同类型的设置时遇到了问题: https://stackoverflow.com/questions/8962477/logrotate-files-with-date-in-the-file-name

配置此功能的一种更简单的方法是将“remots”(rsyslog)日志写入静态位置,例如:

$template GuardaRemots, "/var/log/remots/%HOSTNAME%.log"
:source, !isequal, "localhost" -? GuardaRemots

然后旋转:

/var/log/remots/*.log {
    rotate 178
    daily
    maxage 178
    compress
}

Logrotate 在旋转时会自动附加日期。

相关内容