全部!
我有 3 个不同的 Restful 服务器:w1、w2、w3
引用我的负载均衡器的客户端提供了名为“ip”(ipv4)的 url 参数。请求之间的 url 参数 ip 不同:
curl -XGET http://localhost:8080/api/v1/link?ip=x.x.x.x
我想根据ip参数使用HASH算法平衡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
我怎样才能做到这一点?
谢谢
最佳答案
使用 HAProxy 1.6.4(及更低版本)选择源平衡算法。我认为这个算法应该可以完成你的工作,或者是否有理由选择 balance url_param
?
balance source
hash-type consistent
哈希类型是可选的,但可能很有用。 Here一些进一步的信息。
关于hash - 使用 url_param 值的 HAProxy 平衡器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34331133/