安裝了 Logrotate,兩台伺服器之間複製了 nginx 的設定...但日誌檔案大小不同

安裝了 Logrotate,兩台伺服器之間複製了 nginx 的設定...但日誌檔案大小不同

我有兩個使用 nginx 的 Web 伺服器,兩個伺服器上都安裝了 logrotate,並且 logrotate.conf 和 logrotate.d/nginx 的設定都是相同的。

兩者都將日誌儲存在 /home/websitename/.pm2/logs 中

在第一個網頁伺服器中,日誌的結構如下:

-rw-r--r--. 1 website website   11M Feb 27 13:21 example.com-out-2__2018-02-27_13-21-12.log
-rw-r--r--. 1 website website   11M Feb 27 13:46 example.com-out-2__2018-02-27_13-46-12.log
-rw-r--r--. 1 website website   11M Feb 27 14:00 example.com-out-2__2018-02-27_14-00-12.log
-rw-r--r--. 1 website website   11M Feb 27 14:19 example.com-out-2__2018-02-27_14-19-42.log
-rw-r--r--. 1 website website   11M Feb 27 14:42 example.com-out-2__2018-02-27_14-42-42.log
-rw-r--r--. 1 website website   11M Feb 27 15:09 example.com-out-2__2018-02-27_15-09-12.log
-rw-r--r--. 1 website website   11M Feb 27 15:36 example.com-out-2__2018-02-27_15-36-12.log
-rw-r--r--. 1 website website   11M Feb 27 16:00 example.com-out-2__2018-02-27_16-00-42.log
-rw-r--r--. 1 website website   11M Feb 27 16:24 example.com-out-2__2018-02-27_16-24-42.log
-rw-r--r--. 1 website website   11M Feb 27 16:48 example.com-out-2__2018-02-27_16-48-12.log

正如你所看到的,它們都有一定的檔案大小、每天的日誌檔案的倍數等等...

在第二個網頁伺服器上,日誌記錄僅記錄到單一大檔案。位於相同的 /home/websitename/.pm2/logs 位置。

-rw-rw-r--. 1 website website  19G Mar  9 14:04 example.com-error-0.log
-rw-rw-r--. 1 website website 7.2G Mar  7 06:09 example.com-error-1.log
-rw-rw-r--. 1 website website 5.2G Mar  9 14:04 example.com-out-0.log
-rw-rw-r--. 1 website website 1.2G Feb 23 23:15 example.com-out-1.log

思考error-0 和 error-1 日誌的原因是伺服器重新啟動時,它啟動了一個新日誌。

問題是,如何更改日誌記錄,以便它可以創建較小的文件,而不是在 19GB 類型的文件中創建如此巨大的文件?

我感覺我已經把所有的設定都看遍了,但還是搞不懂!我「認為」logrotate 正在工作,因為當我檢查 logrotate.status 時我得到了當天的狀態。

/etc/logrotate.conf:

這是 /etc/logrotate.conf 檔案:

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
        minsize 1M
    rotate 1
}
/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

/etc/logrotate.d/nginx 檔案:

/var/log/nginx/*.log {
        daily
        missingok
        rotate 4
        compress
        delaycompress
        notifempty
        create 640 nginx adm
        sharedscripts
        postrotate
                if [ -f /var/run/nginx.pid ]; then
                        kill -USR1 `cat /var/run/nginx.pid`
                fi
        endscript
}

相關內容