参考:https://www.cnblogs.com/smail-bao/p/6093122.html
https://www.cnblogs.com/zjz20/p/12809856.html
vim etc/logrotate.d/haproxy,内容如下:
/var/log/haproxy/haproxy.log { #文件绝对路径,weekly,monthly daily #指定转储周期为每天,保留31天的日志 rotate 31 missingok #如果日志文件丢失,不进行显示错误 notifempty #当日志文件为空时,不进行转储 dateext #加上日志格式 compress #通过gzip压缩转储后的日志
delaycompress sharedscripts #转储完成后运行脚本,postrotate-endscript间为脚本内容,脚本效果为重启rsyslogd服务。 postrotate systemctl restart rsyslog.service endscript }
验证,不实际运行:
logrotate -d /etc/logrotate.d/haproxy
添加任务计划,每天5点运行,crontab -e :
0 5 * * * /usr/sbin/logrotate -f /etc/logrotate.d/haproxy