【问题标题】:how to get logs in a haproxy:1.5-alpine Docker container如何在 haproxy:1.5-alpine Docker 容器中获取日志
【发布时间】:2017-10-23 13:59:33
【问题描述】:

从 haproxy:1.5-alpine 构建一个 haproxy 容器

(https://github.com/docker-library/haproxy/blob/1848d2933afbefd0e0a068dc7b5a753ab7842e6c/1.5/alpine/Dockerfile)

haproxy 容器启动良好,但是我如何实现详细的 haproxy 日志记录并将其定向到标准输出。

我的 haproxy 配置是

global
     log /dev/log  local0
    # log /dev/log  local1 notice
    # chroot /var/lib/haproxy
    # stats socket /run/haproxy/admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

    tune.ssl.default-dh-param 2048
    # Default SSL material locations
    #ca-base /etc/ssl/certs
    #crt-base /etc/ssl/private

    ssl-default-bind-options no-sslv3
    ssl-default-bind-ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM
enter code here

defaults
    log global
    mode  http
    option  httplog
    option  dontlognull

    # fixed configuration by Benson
    option  http-keep-alive
    timeout http-keep-alive 5m
    timeout http-request 5s
    timeout connect 300s
    timeout client  300s
    timeout server  300s
    timeout check   300s

    #old configurations causing connection timeouts
    #timeout connect 5000
    #timeout client  50000
    #timeout server  50000

    errorfile 400 /usr/local/etc/haproxy/errors/400.http
    errorfile 403 /usr/local/etc/haproxy/errors/403.http
    errorfile 408 /usr/local/etc/haproxy/errors/408.http
    errorfile 500 /usr/local/etc/haproxy/errors/500.http
    errorfile 502 /usr/local/etc/haproxy/errors/502.http
    errorfile 503 /usr/local/etc/haproxy/errors/503.http
    errorfile 504 /usr/local/etc/haproxy/errors/504.http
    balance roundrobin
    option httpchk

我尝试了通过 docker entrypoint.sh 中的以下命令将日志定向到标准输出的选项

"/bin/sh -c /sbin/syslogd -O /dev/stdout"

#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
        set -- haproxy "$@"
fi

if [ "$1" = 'haproxy' ]; then
        # if the user wants "haproxy", let's use "haproxy-systemd-wrapper" instead so we can have proper reloadability implemented by upstream
        /bin/sh -c /sbin/syslogd -O /dev/stdout
        shift # "haproxy"
        set -- "$(which haproxy-systemd-wrapper)" -p /run/haproxy.pid "$@"
fi

exec "$@"

但是,当我通过 haproxy 浏览应用程序时,没有注册任何日志,尽管它运行良好。

我想知道如何通过 alpine haproxy 容器中的 haproxy 获取详细的日志记录

【问题讨论】:

  • 一个简短的答案,很难;)您需要将 haproxy 指向系统日志。因此,如果您可以将 rsyslog 安装为服务,然后通过 docker_entrypoint.sh 重新启动 rsyslog,应该可以工作,但还是可以? ;)
  • 正在发生日志记录只是因为我需要增加详细级别的方法,因此即使请求日志也会被注册。

标签: docker haproxy alpine


【解决方案1】:

您需要将 /dev/log 从主机传递到容器中,然后从主机端读取您的日志! haproxy 的作者反对将日志记录到标准输出(出于性能原因),所以除了我描述的(或在 pod 的另一个容器中运行 syslog 守护程序)之外,您无能为力

【讨论】:

  • 这适用于 alpine docker 图像。应该被接受为问题的解决方案。
【解决方案2】:

您可以使用 log stdout 语句代替 log rsyslogserver:514 。 参考:Haproxy get logs from docker container

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-26
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 2019-07-26
    • 2020-01-17
    相关资源
    最近更新 更多