使用单个请求获取haproxy两次日志

时间:2018-03-05 07:11:42

标签: linux haproxy

我已经将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"

任何人都可以帮我这个,为什么每个请求存储两次日志? &安培;我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可能已经解决了,但是为了将来的Google员工着想-原因是您在log部分和defaults部分中都拥有frontend指令。如果您从frontend部分中删除该行,则应该只会获得一个日志项。