首页 > 代码库 > haproxy 日志切割
haproxy 日志切割
(1) 取消将日志记录在/var/log/messages目录中
默认会也将haproxy日志记录在/var/log/message中,要去掉。
# vi /etc/rsyslog.conf
local3.* /var/log/haproxy.log
local0.* /var/log/haproxy.log
*.info;mail.none;authpriv.none;cron.none;local3.none /var/log/messages
(2) haproxy日志切割
haproyx日志切割脚本,没有现成的,就专门写了一个日志切割脚本来实现每天的日志切割,加入到计划任务中,一定要su root -c 强制root权限执行。如果要保留访问日志,可以修改脚本实现。
#!/bin/bash
# author: jun
# desc:
# date: 2014-07-07
# version: v1.0
# modify:
# cut haproxy log
mv /var/log/haproxy.log /var/log/haproxy.log.bak
if [ -e /var/log/haproxy.log.bak ]; then
logrotate -f /etc/logrotate.conf
chown nobody:nobody /var/log/haproxy.log
chmod +x /var/log/haproxy.log
fi
sleep 1
if [ -e /var/log/haproxy.log ]; then
rm -rf /var/log/haproxy.log.bak
fi
(3) haproxy配置文件记录
global
log 127.0.0.1 local0
maxconn 65535
chroot /usr/local/haproxy
uid 99
gid 99
stats socket /usr/local/haproxy/HaproxSocket level admin
daemon
nbproc 1
pidfile /usr/local/haproxy/haproxy.pid
#debug
defaults
log 127.0.0.1 local3
mode http
option httplog
option httplog clf
option httpclose
#option dontlognull
option forwardfor
option redispatch
retries 2
maxconn 2000
balance source
#balance roundrobin
stats uri /haproxy-stats
stats refresh 10s
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen APP_Cluster 0.0.0.0:80
mode http
option httpchk GET /test.html HTTP/1.0rnHost:192.168.0.110
server 192.168.0.111_node1 192.168.0.111:80 weight 3 check inter 2000 rise 2 fall 1
server 192.168.0.112_node2 192.168.0.112:80 weight 3 check inter 2000 rise 2 fall 1
server 192.168.0.113_node3 192.168.0.113:80 weight 3 check inter 2000 rise 2 fall 1
listen stats_auth 0.0.0.0:91
mode http
stats enable
stats uri /admin
stats realm "LOGIN"
stats auth admin:123456
#stats hide-version
stats refresh 10s
stats admin if TRUE
(4)重启服务
/etc/init.d/rsyslog restart
/etc/init.d/haproxy restart
本文出自 “Lonely(技术群:1991706)” 博客,请务必保留此出处http://304076020.blog.51cto.com/7503470/1435227