0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Linux】logrotateを使ってログローテションの管理

Last updated at Posted at 2022-02-01

経緯

検証環境でアプリケーションログのログローテーションが設定されていなくてログファイルが肥大化していたので設定を確認

以下のコマンドでサイズの大きいファイルを確認

sudo du -x -h / | sort -r -h |

関連記事

任意のログをlogrotateを使って管理する

設定ファイルの確認

/etc/
├── logrotate.conf # メインの設定ファイル
├── logrotate.d # 各サービスごとの設定ファイル
│   ├── dracut
│   ├── iscsiuiolog
│   ├── mcollective
│   ├── mysql
│   ├── syslog
│   ├── yum

設定例

/var/log/sample-service/sample.log { # 対象のログファイル
    compress           # 圧縮する
    delaycompress      # ログの圧縮作業を次回のローテーション時まで遅らせる。compressと共に指定
    daily              # 毎日ローテートする
    rotate 7           # 7世代分古いログを残す
    size 0             # ログファイルが指定したファイルサイズ以上になったらローテーションする
    ifempty            # ログファイルが空でもローテーションする
    missingok          # ログファイルがなくてもエラーを出さない
    create             # ローテーション後に空のログファイルを新規作成。
}

まとめ

環境をたち上げた後など、容量不足などが発生した場合などはログローテションの設定がされているかなどを確認してみましょう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?