LoginSignup
44
40

More than 5 years have passed since last update.

AWSでlogrotateをサクっと設定する

Posted at

1. 既に雛形が設定されているので、コピーする

今回はPHPのログを取りたいので、ファイル名はPHPにしています。
ファイル名は任意ですが、具体的なサービス名にしておくとわかりやすいです。

sudo cp /etc/logrotate.d/httpd /etc/logrotate.d/php

2. 設定を書く

以下は毎日ローテーションして10日分を.gzで圧縮しておく設定です。

/var/log/php.log {
    missingok
    daily
    compress
    rotate 10
}

logrotateで設定できるオプションについては以下のサイトがわかりやすいです。

@IT:logrotateの設定ファイルで指定できる主なコマンド
http://www.atmarkit.co.jp/flinux/rensai/linuxtips/747logrotatecmd.html

3. 実行テストする

以下コマンドを実行すると動作をテストできます。

sudo /usr/sbin/logrotate -f /etc/logrotate.d/php

4. 設定を反映する

以下コマンドで設定を反映します。

sudo /usr/sbin/logrotate /etc/logrotate.conf

以上です。ログのローテーションは重要ですが、忘れがちなのでメモしておきます。

44
40
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
44
40