1
1

More than 3 years have passed since last update.

Fedora 33 (beta)でログがローテートされない落とし穴

Posted at

環境
Fedora 33(beta) x86_64
cronie-1.5.5-4.fc33.x86_64
cronie-anacron-1.5.5-4.fc33.x86_64
logrotate-3.17.0-3.fc33.x86_64
systemd-246.6-3.fc33.x86_64

症状
logrotateを1時間毎に行いたいが、期待された間隔でローテートされない。

再現手順
(1) Fedora 33 (beta)をミニマムでインストール
(2) cronie, cronie-anacron , crontabsをインストール
(3) rsyslog と logrotate をインストール
(4) /etc/logrotate.d/rsyslog の中で /var/log/messages のローテートに関する
  設定をログローテートの間隔を1時間毎 (hourly)とする。
(5) 数時間待つ

期待される結果
/var/log/messages などが、1時間毎にローテートされる。

実際の結果
/var/log/messages などが、数時間待ってもローテートされない。

原因
logrotateの起動方法のデフォルトがcronからsystemd-timerに変わったため。
logrotateのデフォルトの動作間隔がdailyであるため。

詳細
昔はlogrotate はcron/anacronから行われてきたが、最近はsystemd-timer を
使ってログのローテートを行う方向にFedoraの開発者は持っていきたいと考えて
いるらしい。 
かつては logrotateのRPMパッケージには /etc/cron.daily/logrotateが含ま
れていたが、

* Wed Nov 21 2018 Alejandro Domínguez Muñoz <adomu@net-c.com> - 3.14.0-5
- add make as a build dependency
- replace cron job with a systemd timer unit (#1502085, #1655153)

というタイミングで、この設定ファイルが含まれなくなったようだ。
その代わりに /usr/lib/systemd/system/logrotate.timer, logrotate.service
が含まれるようになっているので、こちらを有効にする必要が有る。

# systemctl enable logrotate.timer

しばらく待ってみるが、1時間毎にログのローテートが実行されない。
その原因は logrotate.timer 内の初期設定にあった。

/usr/lib/systemd/system/logrotate.timer
OnCalendar = daily 

となっているため、一日一回(午前0時過ぎ)にlogrotateが起動されるのが初期設定と
なっている。 そのため、logrotate の設定ファイル内に hourly が書かれていても
1時間毎にlogrotateが実行されないため、ログのローテートは行われなかった。

修正方法

# cp /usr/lib/systemd/system/logrotate.timer /etc/systemd/system/
# cp /usr/lib/systemd/system/logrotate.service /etc/systemd/system/
# vi /etc/systemd/system/logrotate.timer
修正前: OnCalendar=daily
修正後: OnCalendar=hourly

# systemctl daemon-reload
# systemctl enable logrotate.timer

これで期待される動きとなった。

参考
https://bugzilla.redhat.com/show_bug.cgi?id=1757726

1
1
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
1
1