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?

Red Hat - Setup Log Housekeeping

Last updated at Posted at 2024-10-28

Step 1. Modified logrotate configuration

johnny$ sudo vim /etc/logrotate.d/nginx
/var/log/nginx/*.log {
    create 0664 nginx johnny # 產生檔案時的使用者及權限
    daily                    # 每天執行一次 (預設執行時間會在凌晨的 03:00 左右,若有指定時間執行請使用 crontab 方式)
    rotate 30                # 保留30天
    dateext                  # 使用日期當作檔案名稱
    dateyesterday            # 使用昨天的日期當作今天的檔名
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}

Setp 2. Test configuration

johnny$ sudo logrotate -vd /etc/logrotate.d/nginx

Setp 3. Used crontab in specified time.

NOTICE:Chose daily way or crontab way. DO NOT USE BOTH.

johnny$ sudo crontab -e
59 23 * * * /usr/sbin/logrotate -vf /etc/logrotate.d/nginx > /dev/null 2>&1 &
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?