我已经为haproxy配置了三个应用服务器
haproxy.cfg:

global
    log 127.0.0.1 local2
    maxconn 10000

defaults
    log global
    log-format {"type":"haproxy","timestamp":%Ts,"http_status":%ST,"http_request":"%r","remote_addr":"%ci","bytes_read":%B,"upstream_addr":"%si","backend_name":"%b","retries":%rc,"bytes_uploaded":%U,"upstream_response_time":"%Tr","upstream_connect_time":"%Tc","session_duration":"%Tt","termination_state":"%ts"}
    mode http
    option  httplog
    option forwardfor
    option httpclose
    option accept-invalid-http-request
    option dontlognull
    option redispatch
    retries 1
    timeout http-request 40s
    timeout connect 40s
    timeout client 40s
    timeout server 40s

userlist UsersAuth
user viz-status insecure-password VIZ-STATUS

frontend hap-LB
    bind *:80
    log global
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request set-header X-Forwarded-Proto https if { ssl_fc }
    http-request set-header X-Forwarded-Host %[req.hdr(Host)]
    default_backend nginx-nodes
frontend sm-viz
    bind *:8008
    default_backend sm-viz

backend nginx-nodes
    stats enable
    stats hide-version
    stats uri /hap-status
    stats realm Haproxy\ Statistics
    stats auth hap-status:HAP-STATUS
    balance roundrobin
#    option httpchk /feeds/hostname
    server dev-01 10.0.0.1:80 #check
    server dev-02 10.0.0.2:80 #check
    server dev-03 10.0.0.3:80 #check

backend sm-viz
    acl AuthOkay http_auth(UsersAuth)
    http-request auth realm Swarm-Visualizer if !AuthOkay
    balance roundrobin
    option httpchk /
    server dev-01 10.0.0.1:8081 check
    server dev-02 10.0.0.2:8081 check
    server dev-03 10.0.0.3:8081 check

所有的配置工作正常,但是在/var/log/haproxy/haproxy.log文件中,每个请求有两次日志记录
Mar  5 06:37:47 localhost haproxy[1]: 10.0.0.1:34380 [05/Mar/2018:06:37:47.648] hap-LB nginx-nodes/dev-01 0/6/-1/-1/10 503 212 - - SC-- 1/1/0/0/+1 0/0 "GET / HTTP/1.1"
Mar  5 06:37:47 localhost haproxy[1]: 10.0.0.1:34380 [05/Mar/2018:06:37:47.648] hap-LB nginx-nodes/dev-01 0/6/-1/-1/10 503 212 - - SC-- 1/1/0/0/+1 0/0 "GET / HTTP/1.1"
Mar  5 06:37:48 localhost haproxy[1]: 10.0.0.3:34382 [05/Mar/2018:06:37:48.123] hap-LB nginx-nodes/dev-03 0/8/-1/-1/16 503 212 - - SC-- 1/1/0/0/+1 0/0 "GET /favicon.ico HTTP/1.1"
Mar  5 06:37:48 localhost haproxy[1]: 10.0.0.3:34382 [05/Mar/2018:06:37:48.123] hap-LB nginx-nodes/dev-03 0/8/-1/-1/16 503 212 - - SC-- 1/1/0/0/+1 0/0 "GET /favicon.ico HTTP/1.1"

有人能帮我一下吗?为什么每个请求都要存储两次日志?&我该怎么解决?

最佳答案

你现在可能已经解决了这个问题,但是为了将来的谷歌用户的利益-原因是你在log部分和defaults部分都有frontend指令。如果从frontend部分删除该行,则只应获得一个日志项。

关于linux - 一次请求获得两次haproxy日志,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49105160/

10-15 10:33