頻繁に記録されるログをデータを失うことなくlogrotate

頻繁に記録されるログをデータを失うことなくlogrotate

私は遅いクエリをキャプチャしlogrotate、毎週循環して1年の価値を節約したいと思います。ログは次の形式を取ります。

-rw-r-----. 1 mysql  root           1239 Feb 21 18:46 mysqld1-slow.log
-rw-r-----. 1 mysql  root            885 Feb 11 14:48 mysqld2-slow.log
-rw-r-----. 1 mysql  root            885 Feb 22 08:58 mysqld3-slow.log
-rw-rw-rw-. 1 mysql  root            802 Feb 11 14:47 mysqld-slow.log

ログが頻繁に記録されるため、欠落しているものがないことを確認するにはどうすればよいですかlogrotate?プロセス自体ではファイルは生成されず、元のファイルが必要です。私はこれがそれを行うと思います:

/var/log/mysqld*-slow.log {
    missingok
    notifempty
    weekly
    rotate 52
    compress
    delaycompress
    create 0644 mysql root
}

したがって、古いファイルを圧縮して正しい権限で同じファイル名を生成する必要がありますが、logrotateが動作中の書き込みをどのように処理するのかわかりません。

ベストアンサー1

この機能は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 cannot 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 logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.

私はこれを所定の位置に置いた。

おすすめ記事