Ale*_*nko 5 hash load-balancing haproxy
我有 3 个不同的 Restful 服务器:w1、w2、w3
引用我的负载均衡器的客户端提供名为“ip”(ipv4) 的 url 参数。请求之间的 url 参数 ip 是不同的:
curl -XGET http://localhost:8080/api/v1/link?ip=x.x.x.x
Run Code Online (Sandbox Code Playgroud)
我想使用 HASH 算法根据 ip 参数平衡 HAProxy 到 w1、w2、w3。
HAProxy 配置如下:
global
#daemon
maxconn 3000
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
default_backend workers
backend workers
balance url_param ip
hash-type consistent
server w1 localhost:8080 weight 1 maxconn 1000 check
server w2 localhost:8081 weight 1 maxconn 1000 check
server w3 localhost:8082 weight 1 maxconn 1000 check
listen admin
bind *:8088
stats hide-version
stats realm HAProxy\ statistics
stats enable
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
对于 HAProxy 1.6.4(及更低版本),选择源平衡算法。我认为这个算法应该可以完成你的工作或者有选择的理由吗balance url_param?
balance source
hash-type consistent
Run Code Online (Sandbox Code Playgroud)
哈希类型是可选的,但可能很有用。这里有一些进一步的信息。