Linux

Apache, Nginxログの肥大化防止 logrotate

 

CentOS7の場合

# vi /etc/logrotate.d/httpd


/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}


↓変更



#/var/log/httpd/*log {
#    missingok
#    notifempty
#    sharedscripts
#    delaycompress
#    postrotate
#        /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
#    endscript
#}




/var/log/httpd/*log {
    daily
    missingok
    notifempty
    sharedscripts
    rotate 12
    weekly
    delaycompress
    postrotate
        /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
    endscript
}

 

 

CentOS6の場合

# vi /etc/logrotate.d/httpd


/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}


↓変更


/var/log/httpd/*log {
    daily
    missingok
    notifempty
    sharedscripts
    rotate 12
    weekly
    compress
    postrotate
        /bin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}


 

ドライランでテスト

# logrotate -dv /etc/logrotate.d/httpd


running postrotate script
running script with arg /var/log/httpd/*log : "
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
"
removing old log /var/log/httpd/access_log.8
error: error opening /var/log/httpd/access_log.8: No such file or directory

 

 

 

# mv /var/lib/logrotate.status /var/lib/logrotate.status_bak-20180104

# touch /var/lib/logrotate.status

 

強制ログロテート

# logrotate -f /etc/logrotate.conf

 

# httpd -t
# systemctl reload httpd

 

 

 

Nginxの場合の例

# vi /etc/logrotate.d/nginx


/var/log/nginx/*log {
    missingok
    minsize 100M
    notifempty
    sharedscripts
    rotate 12
    weekly
    compress
    postrotate
        kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

 

 

 

Amazonおすすめ

iPad 9世代 2021年最新作

iPad 9世代出たから買い替え。安いぞ!🐱 初めてならiPad。Kindleを外で見るならiPad mini。ほとんどの人には通常のiPadをおすすめします><

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)