- 1. 概要
- 2. ファイル
- 3. 書式
- 4. デバッグ
- 5. 参考サイト
1. 概要
「FreeBSD」は、実機で使い込んでいるので、ログローテーションをあれこれといじりまわしていますが。
「Linux」では、めったにさわることがないので、頭にはいっていないのですが、ちょっとさわる機会があったので、メモを残しておきます。
2. ファイル
定義ファイルを基本的に。
/etc/logrotate.d/
配下に置きます。
3. 書式
定義ファイルの基本的な書式は、下記になります。
/path/to/logfile {
lotation_option
}
主なローテーションオプションは、下記になります。
オプション | 意 味 | 備考 |
size size | ログファイルのサイズが「size」を超えた場合にローテーションを実行 | |
rotate count | ローテーション後のログファイルの数を count に制限し、古いファイルを削除 | |
missingok | ログファイルが存在しない場合でもエラーとしない | |
notifempty | ログファイルが空の場合、ローテーションを実行しない | |
delaycompress | ローテーション時に圧縮を遅延 | |
compress | ローテーション時にログファイルを圧縮 | |
copytruncate | ログファイルをコピーして元のファイルを切り詰め | |
create mode owner group | ローテーション後に新しいログファイルを作成 | |
sharedscripts | prerotate や postrotate スクリプトをすべてのログファイルに対して一度だけ実行 | |
prerotate | ローテーション前に実行するスクリプトを指定 | |
postrotate | ローテーション後に実行するスクリプトを指定 | |
daily, weekly, monthly, yearly | いずれかで、ローテーションの間隔を指定(毎日、毎週、毎月、毎年) | |
dateext | ログファイル名に日付を付加 | |
dateformat | dateext で使用する日付形式 | |
maxage count | ログファイルを保持する最大日数を count で指定 | |
olddir directory | ローテーション後のログファイルを保存するディレクトリを指定 | |
extension | ログファイルの拡張子を指定 | |
4. デバッグ
基本的に、定義を書いておけば、勝手に動いてくれますが。
logrotate
というコマンドで、強制的にローテーションさせたりもできます。
logrotate -d
で、デバッグモードで動いてくれます。
/etc/logrotate.d/laravel
というファイルを作成して(「Laravel」のログローテーションを定義)。
中に下記を記述。
/var/www/html/path/storage/logs/*.log {
daily
rotate 14
missingok
notifempty
copytruncate
}
下記を実行すると。
logrotate -d /etc/logrotate.d/laravel
下記の結果が出力されました。
rotating pattern: /var/www/html/path/storage/logs/*.log after 1 days (14 rotations)
empty log files are not rotated, old logs are removed
Creating new state
Creating new state
considering log /var/www/html/path/storage/logs/laravel.log
error: skipping "/var/www/html/path/storage/logs/laravel.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.
Creating new state
う~ん、よくわからない。
1日たってみないと結果がわからないなぁ。
「FreeBSD」の「newsyslog」に比べると、面倒くさいのだ。
5. 参考サイト
本ページは、下記のサイトを参考にさせていただきました。
「logrotate のテスト方法」
|
|