Logrotate的常见配置

缩小日志大小和备份文件用

如果想测试配置文件

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf

下面是nginx php和mysql的日志设置

/var/log/nginx/*.log {
        daily
        size 1G
        missingok
        rotate 10
        compress
        delaycompress
        notifempty
        create 0640 nobody nobody
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi \
        endscript
        postrotate
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
        endscript
}


/usr/local/php/var/log/php-fpm.log /usr/local/php/var/log/php-fpm.log.slow {
    dateext
    create
    #maxage 90
    rotate 60
    missingok
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /var/run/php-fpm.pid`
    endscript
}

/var/lib/mysql/slow-log /var/lib/mysql/localhost.err {
    dateext
    create
    # notifempty
    #maxage 90
    rotate 60
    missingok
    sharedscripts
    postrotate
        /usr/local/mysql/bin/mysqladmin -uroot -p'password' flush-logs
    endscript
}

标签: mysql, PHP, nginx

本文由 老高 创作,采用 知识共享署名 3.0 中国大陆许可协议 进行许可。
可自由转载、引用,但需署名作者且注明文章出处。

相关文章

添加新评论