1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

logrotate設定(1日単位)

Posted at
  1. 設定ファイルの確認・編集
    /etc/logrotate.d/syslog などに messages の設定があります。
/etc/logrotate.d/syslog
sudo vi /etc/logrotate.d/syslog

(ディストリビューションによっては /etc/logrotate.d/rsyslog や /etc/logrotate.d/syslog-ng などの場合もあります)

2.ローテート設定を以下のように修正・追加

/var/log/messages {
    daily                 # ← 1日ごとにローテート
    rotate 7              # ← 7世代保管(お好みで)
    missingok             # ← ログがなくてもエラーにしない
    notifempty            # ← 空ファイルはローテートしない
    compress              # ← ローテート後に gzip 圧縮
    delaycompress         # ← 1世代後から圧縮
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

/var/run/syslogd.pid は使っているロガーによって変わります:
rsyslog → /var/run/rsyslogd.pid
syslog-ng → /var/run/syslog-ng.pid

3.テスト実行して確認(強制ローテート)

sudo logrotate -f /etc/logrotate.conf

4.cron.daily で自動実行される(設定済み)
通常 logrotate は /etc/cron.daily/logrotate に登録されています。
確認:

ls -l /etc/cron.daily/logrotate
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?