您的位置:首页 > 其它

haproxy配置日志及自定义日志

2017-03-28 09:57 1501 查看
日志级别:
emerg 0 系统不可用
alert 1 必须马上采取行动的事件
crit 2 关键的事件
err 3 错误事件
warning 4 警告事件
notice 5 普通但重要的事件
info 6 有用的信息
debug 7 调试信息
配置记录日志:
在默认情况haproxy是不记录日志的;
通过配置haproxy.cfg使其记录日志
haproxy.cfg:开启haproxy日志记录
log 127.0.0.1 local2
/etc/rsyslog.conf:利用rsyslog接收日志:
去掉这两行的注释:
$ModLoad imudp
$UDPServerRun 514
新增这一行:
local2.* /var/log/haproxy.log
重启rsyslog,查看udp的514端口是否开启:
#/etc/init.d/rsyslog restart
#netstat -tunpl
配置haproxy记录更详细的日志:
默认的日志可读性很差,我们需要显示更多的信息,但默认的都捕获不到,只能自定义需要显示的内容了
capture request header Host len 64
capture request header User-Agent len 128
capture request header X-Forwarded-For len 100
capture request header Referer len 200
capture response header Server len 40
capture response header Server-ID len 40
log-format %ci:%cp\ %si:%sp\ %B\ %U\ %ST\ %r\ %b\ %f\ %bi\ %hrl\ %hsl\
重启haproxy即可

捕获请求头参考官网:http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.8
自定义日志格式参考官网:http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.2.4
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  日志 haproxy