Centos

logrotate 無法截斷 catalina.out

  • February 6, 2019

我在我的 centos 機器上執行 tomcat 伺服器。我的/etc/logrotate.d/tomcat文件中有以下內容:

/log/apache-tomcat/catalina.out{
copytruncate
daily
size 256M
rotate 8
missingok
maxage 7
}

我嘗試logrotate在調試模式下手動執行該命令。

/usr/sbin/logrotate -d /etc/logrotate.conf

在日誌中,我發現了有關該/log/apache-tomcat/catalina.out文件的以下內容。

旋轉模式:/log/apache-tomcat/catalina.out 268435456 字節(8 次旋轉)

空日誌文件被輪換,舊日誌被刪除

考慮日誌 /log/apache-tomcat/catalina.out 日誌需要輪換

旋轉日誌 /log/apache-tomcat/catalina.out,log->rotateCount 為 8

dateext 後綴“-20190206”

全域模式'-

$$ 0-9 $$$$ 0-9 $$$$ 0-9 $$$$ 0-9 $$$$ 0-9 $$$$ 0-9 $$$$ 0-9 $$$$ 0-9 $$' glob 查找舊的旋轉日誌失敗

將 /log/apache-tomcat/catalina.out 複製到 /log/apache-tomcat/catalina.out-20190206

截斷 /log/apache-tomcat/catalina.out

But the file size didn’t change after running the command. I’m not sure what went wrong here. This file size is keep on increasing and causing lot of issues.

The problem got resolved after changing the permissions of /etc/logrotate.d/tomcat file.

Before:

$ ls -lht /etc/logrotate.d/tomcat
-rwxr-xr-x 1 root root 308 Apr 25  2018 /etc/logrotate.d/tomcat

After:

$ sudo chmod -x /etc/logrotate.d/tomcat
$ ls -lht /etc/logrotate.d/tomcat
-rw-r--r-- 1 root root 308 Apr 25  2018 /etc/logrotate.d/tomcat

Got to know about it after checking verbose of logrotate.

$ /usr/sbin/logrotate -v /etc/logrotate.conf

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