haproxy syslog 日志记录简单说明

很多时候我们需要配置日志方便进行异常分析,haproxy 在frontend以及backend 都提供了日志配置,以下是一个配置简单说明

参考配置

  • haproxy frontend http 日志
global
    log 127.0.0.1:514 local2
    chroot /var/lib/haproxy
    stats socket /run/haproxy/haproxy.sock mode 600 level admin
    pidfile /var/run/haproxy.pid
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

frontend  hasura_frontend
    bind :18080
    mode http
    option httplog
    log 127.0.0.1:514 local2 info
    default_backend  hasura_backend

  • backend health-checks log
backend fs_backend
    balance roundrobin
    mode http
    option httpchk
    option log-health-checks
    log 127.0.0.1:514 local2 info
    server  demo 127.0.0.1:5000 weight 7 check inter 2000
  • rsyslog
module(load="imudp") # needs to be done just once
input(type="imudp" port="514")
local2.*        /var/log/haproxy/haproxy.log

说明

比较怪异的地方是需要再frontend 明确指定syslog 配置之后才能看到,否则是不会写数据到syslog 中的,以上就是一个记录,方便使用

参考资料

https://www.haproxy.com/blog/introduction-to-haproxy-logging

https://www.haproxy.com/documentation/haproxy-configuration-manual/1-8r1/#8.2.3

https://www.haproxy.com/documentation/haproxy-configuration-manual/1-8r1/#option%20httplog

posted on 2025-06-29 08:00  荣锋亮  阅读(31)  评论(0)    收藏  举报

导航