Linux

/var/log/messages - 旋轉時不壓縮

  • October 25, 2019

我正在嘗試壓縮消息,因為它的大小越來越大,而且空間不大。我嘗試了所有來自 - compress-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 

任何幫助將不勝感激。

好的,logrotate由於缺少日誌文件,您失敗了。當您使用時,logrotate -d您會得到詳細的調試輸出,但是logrotate does not do anything. 如果你先做

logrotate -v logrotate-message -f

取而代之的是 force 選項,結合詳細輸出將向您顯示-f標誌的操作,這man logrotate將創建失去的日誌文件,以防止與未找到以前的日誌文件相關的錯誤。

您沒有找到 4 個日誌存檔,因為在前兩個文件名中,您有一個-a.應該在的位置,並且模式正則表達式因此而失敗。嘗試手動更正或logrotate -f先刪除這些後創建它。

此外,您對特定messages配置文件的格式設置有點麻煩。沒有理由在包含單個腳本的括號上方有配置選項messages(因為它可以覆蓋全域配置選項,具體取決於它們的讀取方式),您應該將compress和其他標誌移入其中。

引用自:https://unix.stackexchange.com/questions/548624