私は nginx を使用する 2 つの Web サーバーを持っており、両方に logrotate をインストールしており、logrotate.conf と logrotate.d/nginx の設定は両方とも同じです。
どちらもログを/home/websitename/.pm2/logsに保存します。
最初の Web サーバーでは、ログは次のように構造化されます。
-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
ご覧のとおり、これらはすべて特定のファイル サイズ、1 日あたりのログ ファイルの倍数などです。
2 番目の Web サーバーでは、ログは単一の大きなファイルにのみ記録されます。同じ /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 ログの原因は、サーバーが再起動され、新しいログが開始されたときです。
質問は、この巨大なオールインワン 19 GB タイプのファイルではなく、より小さなファイルを作成するようにログ記録を変更するにはどうすればよいかということです。
すべての設定を確認したのですが、わかりません。logrotate.status を確認すると現在の日付のステータスが表示されるので、logrotate は動作していると思います。
/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
}