[root@hy1 logrotate.d]# pwd
/etc/logrotate.d
[root@hy1 logrotate.d]# ls nginx php-fpm mysql
mysql nginx php-fpm
[root@hy1 logrotate.d]# cat nginx
/data/nginx/logs/*.log {
daily
rotate 7
missingok
notifempty
sharedscripts
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}
[root@hy1 logrotate.d]# cat php-fpm
/usr/local/webserver/php/var/log/*.log {
daily
rotate 7
missingok
notifempty
sharedscripts
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /usr/local/webserver/php/var/run/php-fpm.pid`
fi
endscript
}
[root@hy1 logrotate.d]# cat mysql
/home/mysql_slow/mysql_slow.log {
daily
rotate 7
dateext
compress
missingok
#notifempty
sharedscripts
create 644 mysql mysql
postrotate
/data/mysql/bin/mysqladmin flush-logs
endscript
}
最后一个mysql 运行需要指定用户名和密码
或者在my.cnf中加入:
-
[mysqladmin]
-
user = root
-
password = *******
-
[root@hy1 logrotate.d]# crontab -l
-
59 23 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx
-
59 23 * * * /usr/sbin/logrotate -f /etc/logrotate.d/php-fpm
-
59 23 * * * /usr/sbin/logrotate -f /etc/logrotate.d/mysql
阅读(1856) | 评论(0) | 转发(0) |