haproxy日志配置

haproxy日志配置

配置HAProxy记录日志到指定日志文件中

在global配置项定义

log 127.0.0.1 local3 info
log 127.0.0.1 local{1-7} info #基于syslog记录日志到指定设备,级别有(err、warning、info、debug)

引用global

listen web_port
	bind 192.168.1.101:80
	mode http
	log global
	server web1 192.168.1.103:80 check inter 3000 fall 2 rise 5

Rsyslog配置

root@z1:~# vim /etc/rsyslog.conf
# provides UDP syslog reception
module(load="imudp")
input(type="imudp" port="514")
local3.*   /var/log/haproxy.log

访问验证是否生成log 文件

root@z1:~# systemctl restart haproxy
root@z1:~# systemctl restart rsyslog
root@z1:~# tail -f /var/log/haproxy.log 
2020-03-31T14:09:26+08:00 localhost haproxy[1892]: Connect from 192.168.1.105:45418 to 192.168.1.101:80 (web_port/HTTP)
自定义日志格式

​ 将特定信息记录在日志中

配置选项
capture cookie <name> len <length> #捕获请求和响应报文中的 cookie并记录日志
capture request header <name> len <length> #捕获请求报文中指定的首部内容和长度并记录日志
capture response header <name> len <length> #捕获响应报文中指定的内容和长度首部并记录日志

示例:

 capture request header Host len 256
 capture request header User-Agent len 512 
 capture request header Referer len 15
配置示例
listen web_host
 bind 192.168.1.101:80
 mode http
 balance roundrobin
 log global
 option httplog #日志格式选项
 capture request header X-Forwarded-For len 15
 capture request header User-Agent len 512
 cookie SERVER-COOKIE insert indirect nocache
 server web1 192.168.1.103:80 cookie web1 check inter 3000 fall 3 rise 5
 server web2 192.168.1.104:80 cookie web2 check inter 3000 fall 3 rise 5
验证日志格式

mark

注意:

​ 虽然可以记录日志,但是一般不在haproxy 上记录日志。通常在后端web 服务器上记录,记得更详细。在haproxy 记日志是为了debug 排错用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值