分享nginx/php/mysql日志轮循的脚本
本文介绍的日志轮循脚本,全部在/etc/logrotate.d目录中。
用命令查看下目录位置:
/etc/logrotate.d
检查下脚本文件是否存在:
mysql nginx php-fpm
1,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
}
2,php日志轮循脚本
/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
}
3,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中加入:
user = root
password = ****1601
[root@jbxue 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
您可能感兴趣的文章:
分享nginx/php/mysql日志轮循的脚本
shell脚本:MySQL慢查询日志和错误日志按天轮询
分享一个shell for循环+case的脚本(监控程序状态)
shell awk读取Nginx 5分钟内的访问日志数
php系统日志切割的实例
分析apache日志中蜘蛛爬行记录数量的shell脚本(图文)
删除及设置linux日志笔记
mysql超出最大连接数的原因剖析
Linux系统下nginx php实现清理服务器网站日志
logrotate对MySQL日志轮替的实例分享