HAProxy 在系统日志中记录 TCP 流量

HAProxy 在系统日志中记录 TCP 流量

我正在尝试配置我的 HAProxy 来记录更多信息,而不仅仅是说“代理 backend_xx 已启动”,但看起来我无法理解它是如何工作的。

我的 HAProxy 是纯 TCP LB(仅将请求从前端转发到后端,纯 L4)。

我想要获取 HAProxy 文档中提到的日志https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#8.2.2

这是我目前的配置和问题,在“全局/默认部分”,我有:

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    daemon
    user                haproxy
    group               haproxy
    log                 /dev/log local6 debug
    maxconn             50000
    chroot              /var/lib/haproxy
    pidfile             /var/run/haproxy.pid

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                 tcp
    option               tcplog
    log                  global
    option               dontlognull
    timeout connect      5000
    timeout client       50000
    timeout server       50000

我的前端下也有这个选项:

frontend main_https_listen
    bind xxxxxxxxxxxxxx:443
    mode                tcp
    option              tcplog
    xxxxxxx

我在我的 rsyslog.d 中配置了一个文件:

[root@xxxxxxx ~]# cat /etc/rsyslog.d/haproxy.conf
# -----------------------------------------------
# Haproxy specific logging configuration
# -----------------------------------------------
local6.debug             /var/log/haproxy-traffic.log
local6.notice            /var/log/haproxy-admin.log
[root@xxxxxxx ~]#

不幸的是,两个文件都包含相同的信息,例如:

[root@xxxxxxx ~]# tail -11 /var/log/haproxy-admin.log
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy stats started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy main_https_listen started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT35073 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT34305 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT28548 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT28756 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT36702 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_UAT_AT28546 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_PRD_AT28547 started.

[root@xxxxxxx ~]# tail -11 /var/log/haproxy-traffic.log
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy stats started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy main_https_listen started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT35073 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT34305 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT28548 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT28756 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_SIT_AT36702 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_UAT_AT28546 started.
Feb 25 18:05:30 xxxxxxx haproxy[838761]: Proxy backend_PRD_AT28547 started.

虽然我希望流量日志能够生成类似文档中的内容,例如:

Feb  6 12:12:56 localhost \
  haproxy[14387]: 10.0.1.2:33313 [06/Feb/2009:12:12:51.443] fnt \
  bck/srv1 0/0/5007 212 -- 0/0/0/0/3 0/0

知道我的配置有什么问题吗?

再次感谢

问候

答案1

我发现了这个问题。我必须在“前端”块下添加一个“全局日志”来告诉前端在那里记录:

frontend main_https_listen
    bind xxxxxx:443
    mode                tcp
    option              tcplog
    log                 global

就这么简单。我现在可以看到日志,例如:

Feb 27 18:05:20 xxxxx haproxy[1392050]: xxxxx:61767 [27/Feb/2020:18:05:14.532] main_https_listen backend_PRD_AT28779/server_PRD_AT28779_1 3/1/6315 4031 -- 0/0/0/0/0 0/0
Feb 27 18:05:20 xxxxx haproxy[1392050]: xxxxx:61767 [27/Feb/2020:18:05:14.532] main_https_listen backend_PRD_AT28779/server_PRD_AT28779_1 3/1/6315 4031 -- 0/0/0/0/0 0/0

相关内容