簡體   English   中英

如何使用php日志配置logrotate

[英]How to configure logrotate with php logs

我正在運行帶有APC的php5 FPM作為操作碼和應用程​​序緩存。 像往常一樣,我將php錯誤記錄到文件中。

由於這變得非常大,我嘗試配置logrotate。 它可以工作,但是在輪換之后,php會繼續記錄到現有的日志文件,即使重命名它也是如此。 這導致scripts.log為0B文件,scripts.log.1繼續增長。

我認為(還沒試過)在postrotate中運行php5-fpm重載可以解決這個問題,但這樣每次都會清除我的APC緩存。

有誰知道如何正常工作?

我發現logrotate的“copytruncate”選項可確保inode不會更改。 基本上什么是[原文如此!]正在尋找。

這可能就是你要找的東西。 摘自: logrotate如何工作? - Linuxquestions.org

正如我在評論中所寫,您需要阻止PHP寫入相同(重命名)的文件。 復制文件通常會創建一個新文件,並且截斷也是該選項名稱的一部分,所以我認為, copytruncate選項是一個簡單的解決方案( 來自聯機幫助頁 ):

  copytruncate Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one, It can be used when some program can not be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some log- ging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place. 

也可以看看:

我在我的服務器上找到的另一個解決方案是告訴php重新打開日志。 我認為nginx也有這個功能,這讓我覺得它一定是很常見的地方。 這是我的配置:

/var/log/php5-fpm.log {
        rotate 12
        weekly
        missingok
        notifempty
        compress
        delaycompress
        postrotate
                invoke-rc.d php5-fpm reopen-logs > /dev/null
        endscript
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM