【发布时间】:2023-03-09 21:57:01
【问题描述】:
我已经为 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"
谁能帮我解决这个问题,为什么每个请求要存储两次日志?以及我该如何解决这个问题?
【问题讨论】: