1、nginx.logrotate(error.log)
/usr/local/nginx/logs/error.log { dateext create #maxage 90 rotate 60 missingok sharedscripts postrotate /bin/kill -USR1 `cat /var/run/nginx.pid` endscript }
2、php.logrotate(php-fpm.log、php-fpm.log.slow)
/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 }
3、mysql.logrotate(slow-log、localhost.err)
/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 }
注:
dateext 每天执行一次,同时转储旧日志时用日期格式"YYMMDD"代替简单的数字作为标记
例:error.log-20110317
create 创建新的日志文件
notifempty 如果是空文件的话,不转储
maxage 90 只存储最近90天的日志文件,超过90天则删除
rotate 60 指定日志文件删除之前转储的次数,此处保留60个备份
missingok 如果日志文件丢失,不报错继续执行下一个
postrotate 在做完 logrotate 之后启动的指令
重新打开日志文件,如果不执行,则无法将日志写进新建立的日志文件中
/bin/kill -USR1 `cat /var/run/php-fpm.pid`
/bin/kill -USR1 `cat /var/run/nginx.pid`
/usr/local/mysql/bin/mysqladmin -uroot -p'password' flush-logs
logrotate 配置文件:
/etc/logrotate.conf
/etc/logrotate.d/*
logrotate测试命令:
logrotate -f /etc/logrotate.conf
logrotate -f /etc/logrotate.d/nginx.logrotate
logrotate -f /etc/logrotate.d/php.logrotate
logrotate -f /etc/logrotate.d/mysql.logrotate