/var/log/messages - 旋转时不压缩

/var/log/messages - 旋转时不压缩

我正在尝试压缩消息,因为它的大小越来越大并且没有太多空间。我尝试了所有来自 -压缩消息- 压缩消息但它与

glob finding old rotated logs failed

我的 logrotate 与链接中的类似

# cat logrotate-message; logrotate -d logrotate-message -f;ls -lrth /var/log/messages*
daily
rotate 7
create
dateext
dateformat .%Y%m%d
compress
notifempty
nomail
noolddir
/var/log/messages {
    rotate 5
    daily
    postrotate
        /bin/killall -HUP syslogd
    endscript
}
reading config file logrotate-message
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /var/log/messages  forced from command line (5 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/messages
  log needs rotating
rotating log /var/log/messages, log->rotateCount is 5
Converted ' .%Y%m%d' -> '.%Y%m%d'
dateext suffix '.20191024'
glob pattern '.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
renaming /var/log/messages to /var/log/messages.20191024
creating new /var/log/messages mode = 0600 uid = 0 gid = 0
running postrotate script
running script with arg /var/log/messages: "
        /bin/killall -HUP syslogd
"
compressing log with: /bin/gzip
-rw------- 1 root root 1016K Sep 29 03:13 /var/log/messages-20190929
-rw------- 1 root root 1020K Oct  6 03:34 /var/log/messages-20191006
-rw------- 1 root root  2.2G Oct 23 11:31 /var/log/messages.20191023
-rw------- 1 root root  735M Oct 24 15:41 /var/log/messages 

任何帮助将不胜感激。

答案1

好的,您的logrotate失败是因为缺少日志文件。当您使用时,logrotate -d您会得到详细的调试输出,但是logrotate does not do anything。如果你首先这样做

logrotate -v logrotate-message -f

相反,强制选项与详细输出相结合将向您显示-f标志的操作,该标志man logrotate将创建丢失的日志文件,以防止与未找到先前日志文件相关的错误。

您没有找到 4 个日志存档,因为在前两个文件名中,您有-a 应该在的位置.,并且模式正则表达式因此失败。尝试手动更正或logrotate -f先删除这些内容后创建它。

另外,您对特定messages配置文件的格式化有点麻烦。没有理由在包含单个脚本的括号上方添加配置选项messages(因为这可以覆盖全局配置选项,具体取决于它们的读取方式),并且您应该将compress和其他标志移到其中。

相关内容