LoginSignup
0
3

More than 5 years have passed since last update.

【logrotate】を触ってみる

Posted at

※古いアカウントに載せてた分を1つにまとめたメモ書きです。

logrotate設定

初期の設定ファイルの中身

/etc/logrotate.conf
 1 # see "man logrotate" for details
 2 # rotate log files weekly
 3 weekly
 4
 5 # keep 4 weeks worth of backlogs
 6 rotate 4
 7
 8 # create new (empty) log files after rotating old ones
 9 create
10
11 # use date as a suffix of the rotated file
12 dateext
13
14 # uncomment this if you want your log files compressed
15 #compress
16
17 # RPM packages drop log rotation information into this directory
18 include /etc/logrotate.d
19
20 # no packages own wtmp and btmp -- we'll rotate them here
21 /var/log/wtmp {
22     monthly
23     create 0664 root utmp
24         minsize 1M
25     rotate 1
26 }
27
28 /var/log/btmp {
29     missingok
30     monthly
31     create 0600 root utmp
32     rotate 1
33 }
34
35 # system-specific logs may be also be configured here.

今回のlogrotate要件

  • 5MBを超えたら世代交代
  • 最大世代数は10まで
  • 世代交代時に圧縮もしてほしい
  • ログファイルがない時のエラーは無視

設定ファイル追加

以下の設定ファイルを追加。

/etc/logrotate.d/test-log
 1 /jobs/log/job-0001.log  {
 2         size 5M
 3         compress
 4         missingok
 5         rotate 10
 6 }
 7 /jobs/log/sample.log  {
 8         size 5M
 9         compress
10         missingok
11         rotate 10
12 }

はじめ、「*.log」としていたが、5MB超えてないファイルまでローテーションされたため別で記述。てっきり勝手にファイル毎に見てくれるんじゃないかと(ry

オプション

  • -d・・・デバックモードで実行
  • -v・・・詳細表示
  • -f・・・強制実行
コマンド実行例.
logrotate -dv /etc/logrotate.d/test-log
logrotate -f /etc/logrotate.d/test-log
0
3
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
3