HAProxy Lua 日志记录

我的 LUA 脚本中出现了重复的 HAProxy 日志消息,我不理解为什么。

haproxy.cfg

global
        log /dev/log local0 warning
        chroot /var/lib/haproxy
        stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
        stats timeout 30s
        user haproxy
        group haproxy
        daemon

        # 默认 SSL 材料位置
        ca-base /etc/ssl/certs
        crt-base /etc/ssl/private

        # 参见:https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
        ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
        ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
        ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
        lua-load /home/tester/hello.lua

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000
        errorfile 400 /etc/haproxy/errors/400.http
        errorfile 403 /etc/haproxy/errors/403.http
        errorfile 408 /etc/haproxy/errors/408.http
        errorfile 500 /etc/haproxy/errors/500.http
        errorfile 502 /etc/haproxy/errors/502.http
        errorfile 503 /etc/haproxy/errors/503.http
        errorfile 504 /etc/haproxy/errors/504.http

frontend test_endpoint
  bind *:9202
  http-request lua.tester

hello.lua

function tester(txn)
  core.log(core.debug, "debug message!\n")
  core.log(core.info, "info message!\n")
  core.log(core.warning, "warning message!\n")
  core.log(core.err, "error message!\n")
end

core.register_action('tester', {'http-req'}, tester)

由于 HAProxy 是作为一个软件包安装的,因此默认情况下会向 /var/log/haproxy.log 写入日志。这是我在日志文件中看到的:

Jan 25 05:47:23 ubuntu haproxy[65622]: warning message!.
Jan 25 05:47:23 ubuntu haproxy[65622]: error message!.
Jan 25 05:47:23 ubuntu haproxy[65615]: [info] 024/054723 (65622) : info message!.
Jan 25 05:47:23 ubuntu haproxy[65615]: [warning] 024/054723 (65622) : warning message!.
Jan 25 05:47:23 ubuntu haproxy[65615]: [err] 024/054723 (65622) : error message!.

我只期望看到顶部的两行消息。 有没有人能解释为什么日志文件中出现了其他行,以及我如何将它们配置在外面?

提前感谢!

供信息参考:

# haproxy -v
HA-Proxy version 2.2.8-1ppa1~bionic 2021/01/14 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2025.
Known bugs: http://www.haproxy.org/bugs/bugs-2.2.8.html
Running on: Linux 4.15.0-134-generic #138-Ubuntu SMP Fri Jan 15 10:52:18 UTC 2021 x86_64

更新:

查看 hlua.c 源代码,我可以看到额外的 3 行是 stderr - 日志记录被发送到日志文件(绿色框)和 stderr(红色框):

enter image description here

点赞
用户53978
用户53978

我不得不在 /lib/systemd/system/haproxy.service 的 ExecStart 中添加“-q”标志。 现在它看起来像这样:

ExecStart=/usr/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE -q $EXTRAOPTS

注意:在 haproxy.cfg 的全局部分中添加“quiet”对我没有起作用。可能是坏了?

2021-01-26 04:03:16