大网数据广告活动
服务器运维问答

HAProxy logging TCP traffic in syslog

· 52CE 我爱测

i'm trying to configure my HAProxy to log more information than just saying "proxy backend_xx started" and it looks like i am failing to understand how it works. my HAProxy is a pure TCP LB (just forwards requests from the fronte…

问题原文

原帖链接 · olivierg · CC BY-SA 4.0

i'm trying to configure my HAProxy to log more information than just saying "proxy backend_xx started" and it looks like i am failing to understand how it works.

my HAProxy is a pure TCP LB (just forwards requests from the frontend to backends, pure L4).

i would like to have logs as mentionned in the HAProxy documentation here https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#8.2.2

here is my configuration & issues at the moment, in the "global/default sections", i have :

#---------------------------------------------------------------------
# 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

i also have this option under my frontend :

frontend main_https_listen
    bind xxxxxxxxxxxxxx:443
    mode                tcp
    option              tcplog
    xxxxxxx

i configured a file in my rsyslog.d with :

[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 ~]#

unfortunately, both files contain the same information, e.g:

[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.

while i would expect having the traffic log to generate things like in the documentation, e.g:

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

any idea on what is wrong in my configuration ?

thanks again

regards

已采纳解答

原帖链接 · olivierg · CC BY-SA 4.0

i found the issue. i had to add a "log global" under the "frontend" block to tell the frontend to log there:

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

as simple as that. i can see the logs now, e.g:

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-02-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。