2019.04.05

logrotate ~ ログがローテートされないときに~

次世代システム研究室の Y.I. です。
 
logrotate について小さな学びがありましたので “自戒” と “備忘録” も兼ねてまとめます。

学びとは、「logrotate の設定が正しくてもログローテーションされない事がある」、「dry-run による実行確認は大事」、です。
 

ローテーション対象の親ディレクトリのパーミッションが 775 or 777 だとローテーションされない

 
ローテーションを指定して実行したところ、下記エラーメッセージが表示されました。
 
[ error: skipping “/var/log/ap_server/app.20190401.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. ]
 
こちらの内容は、ローテート対象の親ディレクトリのパーミッションが誰でも書き込める 777 または 同一グループユーザーが書き込める775 だとローテーションできないというエラーメッセージになります。
$ sudo logrotate -d /etc/logrotate.d/app
reading config file /etc/logrotate.d/appAllocating hash table for state file, 
size 15360 BHandling 1 logsrotating pattern: "/var/log/ap_server/*.log" after 1 days (10 rotations)empty log files are not rotated, 
old logs are removedconsidering log /var/log/ap_server/app.20190401.log
error: skipping "/var/log/ap_server/app.20190401.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.
 

解決策は2つあります。

  1.  親ディレクトリのパーミッションを 755 へ変更する
    (こちらは説明を省略します)
  2.  ローテートするユーザーを設定で指定する
    /etc/logrotate.d/xxx にて、 su ディレクティブでユーザーを指定する
    "/var/log/ap_server/*.log" { 
    ・・・
    su osuser group
    ・・・
    }
 

dry-run による実行確認は大事

 
テスト環境でも運用中の本番環境でも logrotate を実際には実行せずに実行したらどのようになるかを試せる dry-run(リハーサル)モードがあるのでいつでも気軽に試せます。
 
-d をつけることで dry-run(リハーサル)モードで実行できます
$ sudo logrotate -d /etc/logrotate.d/app
reading config file /etc/logrotate.d/appAllocating hash table for state file, 
size 15360 BHandling 1 logsrotating pattern: "/var/log/ap_server/*.log" after 1 days (10 rotations)empty log files are not rotated, 
old logs are removedswitching euid to 1001 and egid to 502
considering log /var/log/ap_server/app.log
log does not need rotating (log has been already rotated)switching euid to 0 and egid to 0
 

最後に

次世代システム研究室では、グループ全体のインテグレーションを支援してくれるアーキテクトを募集しています。アプリケーション開発の方、次世代システム研究室にご興味を持って頂ける方がいらっしゃいましたら、ぜひ 募集職種一覧 からご応募をお願いします。

皆さんのご応募をお待ちしています。
 

  • Twitter
  • Facebook
  • はてなブックマークに追加

グループ研究開発本部の最新情報をTwitterで配信中です。ぜひフォローください。

 
  • AI研究開発室
  • 大阪研究開発グループ

関連記事