1、
mkdir -p /mysql/data
mkdir -p /mysql/log
chmod 777 -R /mysql/log
chmod 777 -R /mysql/data
2、
[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
网友评论