作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已经配置了三个应用服务器的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"
谁能帮我解决这个问题,为什么每个请求要存储两次日志? & 我该如何解决这个问题?
最佳答案
你现在可能已经解决了它,但为了 future googlers 的利益 - 原因是你在 defaults
部分和你的中都有 log
指令前端
部分。如果您从 frontend
部分中删除该行,您应该只会得到一个日志项。
关于linux - 使用单个请求获取 haproxy 两次日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49105160/
我是一名优秀的程序员,十分优秀!