Linux

為什麼我仍然看到舊的日誌文件而沒有新的?

  • May 3, 2020

這是我的設置 logrotate

/home/sy/logs/kitxit*/*/tend.log
   {
       daily
       rotate 10
       dateext
       compress
       delaycompress
       copytruncate
       missingok
       notifempty
       su apache apache
   }

輸出如下

drwxr-xr-x 2 apache apache     4096 Apr 30 13:00 .
drwxr-xr-x 6 apache apache     4096 Apr 30 13:00 ..
-rw-r--r-- 1 apache apache 21318609 May  2 21:25 tend.log
-rw-r--r-- 1 apache apache     4091 Feb 24 03:02 tend.log-20200224.gz
-rw-r--r-- 1 apache apache     4065 Feb 25 03:02 tend.log-20200225.gz
-rw-r--r-- 1 apache apache     4460 Feb 26 03:03 tend.log-20200226.gz
-rw-r--r-- 1 apache apache     4049 Feb 27 03:03 tend.log-20200227.gz
-rw-r--r-- 1 apache apache     2619 Feb 28 03:03 tend.log-20200228.gz
-rw-r--r-- 1 apache apache     1312 Feb 29 03:03 tend.log-20200229.gz
-rw-r--r-- 1 apache apache     1339 Mar  1 03:03 tend.log-20200301.gz
-rw-r--r-- 1 apache apache     1305 Mar  2 03:03 tend.log-20200302.gz
-rw-r--r-- 1 apache apache     2669 Mar  3 03:02 tend.log-20200303.gz
-rw-r--r-- 1 apache apache    70011 Mar  4 03:03 tend.log-20200304

為什麼我仍然看到舊的日誌文件而沒有新的?

這是調試模式的結果

[root@xavs-ken logrotate.d]# logrotate -dv kitxit-tend-sylog
reading config file kitxit-tend-sylog
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /home/sy/logs/kitxit*/*/tend/*.log
/home/sy/logs/kitxit*/*/sylog/*.log
after 1 days (10 rotations)
empty log files are not rotated, old logs are removed
switching euid to 48 and egid to 48
considering log /home/sy/logs/kitxit2/bola/tend/sql.log
 log needs rotating
considering log /home/sy/logs/kitxit2/bola/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/bola/tend/mem.log
 log does not need rotating (log is empty)considering log /home/sy/logs/kitxit/bola/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/clpl/tend/sql.log
 log needs rotating
considering log /home/sy/logs/kitxit/clpl/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/mol/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/pola/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/solsa/tend/sql.log
 log needs rotating
considering log /home/sy/logs/kitxit/solsa/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/sario/tend/mem.log
 log does not need rotating (log is empty)considering log /home/sy/logs/kitxit/sario/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/sasu/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/kilo/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/mixi/tend/mem.log
 log does not need rotating (log is empty)considering log /home/sy/logs/kitxit/mixi/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/aziz/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit/xondana/tend/tend.log
 log needs rotating
considering log /home/sy/logs/kitxit2/bola/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/bola/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/clpl/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/mol/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/pola/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/solsa/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/entag/sylog/action.log
 log does not need rotating (log is empty)considering log /home/sy/logs/kitxit/sario/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/sasu/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/kilo/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/mixi/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/aziz/sylog/action.log
 log needs rotating
considering log /home/sy/logs/kitxit/xondana/sylog/action.log
 log needs rotating
rotating log /home/sy/logs/kitxit2/bola/tend/sql.log, log->rotateCount is 10
dateext suffix '-20200503'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding logs to compress failed
copying /home/sy/logs/kitxit2/bola/tend/sql.log to /home/sy/logs/kitxit2/bola/tend/sql.log-20200503
truncating /home/sy/logs/kitxit2/bola/tend/sql.log
rotating log /home/sy/logs/kitxit2/bola/tend/tend.log, log->rotateCount is 10
dateext suffix '-20200503'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding logs to compress failed
glob finding old rotated logs failed

調試輸出中的日誌文件與配置文件中的 logrotate 路徑不對應。

tend.log調試輸出中匹配的文件

considering log /home/sy/logs/kitxit2/bola/tend/tend.log
considering log /home/sy/logs/kitxit/clpl/tend/tend.log
considering log /home/sy/logs/kitxit/mol/tend/tend.log
considering log /home/sy/logs/kitxit/pola/tend/tend.log
considering log /home/sy/logs/kitxit/solsa/tend/tend.log
considering log /home/sy/logs/kitxit/sasu/tend/tend.log
considering log /home/sy/logs/kitxit/kilo/tend/tend.log
considering log /home/sy/logs/kitxit/aziz/tend/tend.log
considering log /home/sy/logs/kitxit/xondana/tend/tend.log

日誌旋轉配置

/home/sy/logs/kitxit*/*/tend.log

該模式需要進行如下修改以匹配正在考慮的文件,即*/路徑中的另一個

/home/sy/logs/kitxit*/*/*/tend.log

由於調試輸出中引用了您的目標文件,我推測在 3 月 4 日/5 日左右停止工作的某個地方還有另一個 logrotate 片段。

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