logrotate分割apache日誌

logrotate配置文件:
apache

[root@localhost ~]<20181212 11:48:47># cat /etc/logrotate.d/httpd
/usr/local/apache/logs/access.log {
        daily
        rotate 30
        create
        missingok
        notifempty
        dateext
        sharedscripts
        postrotate
            /usr/local/apache/bin/httpd -k graceful > /dev/null 2>/dev/null || true
        endscript
}
#或者/bin/kill -SIGUSR1 `cat /usr/local/apache/logs/httpd.pid 2>/dev/null` 2>/dev/null || true。對比graceful好點。若是配置文件錯誤,graceful不會形成httpd服務異常。


#若是怕安全重啓服務會形成服務異常, 能夠不重啓服務,而是使用copytruncate選項。他是先拷貝日誌,而後清空日誌的方式。拷貝開始和拷貝結束之間的日誌會丟失(通常1-2秒鐘)。把上面的sharedscripts和postrotate和endscript這幾行刪除。



設置定時任務:安全

也能夠不設置定時任務,由於logrotate會自動分割,時間大概是凌晨3點左右。bash

1 0 * * * /usr/sbin/logrotate -f /etc/logrotate.d/httpd > /dev/null 2>&1
相關文章
相關標籤/搜索