使用Haproxy LoadBalancer使用自定义哈希功能
我已经在前端使用Haproxy配置了负载平衡器,在后端我有4个服务器使用Apache Web服务器服务请求。
#HAProxy for web servers
frontend web-frontend
bind IPADDRESS_LB:80
mode http
default_backend web-backend
backend web-backend
balance roundrobin
server web-server1 IPADDRESS1:80 check
server web-server2 IPADDRESS2:80 check
server web-server3 IPADDRESS3:80 check
server web-server4 IPADDRESS4:80 check
我的要求是由循环机制中的任何一种机器提供的。但是现在,我想实现自己的算法,以根据请求参数(例如IP)发送请求。
就像根据我可以将请求路由到一个后端服务器的结果来实现自己的哈希功能一样。
我该怎么做?
I have configured a load balancer using HAProxy on frontend and on the backend I have 4 server serving the request using Apache web server.
#HAProxy for web servers
frontend web-frontend
bind IPADDRESS_LB:80
mode http
default_backend web-backend
backend web-backend
balance roundrobin
server web-server1 IPADDRESS1:80 check
server web-server2 IPADDRESS2:80 check
server web-server3 IPADDRESS3:80 check
server web-server4 IPADDRESS4:80 check
My requests are served by either of the machines in a round robin mechanism. But now I want to implement my own algorithm to send the request based on the request parameters, eg IP.
Like Implementing my own hash function based on the result of which I can route my request to either of the backend servers.
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以参数化在哈希中使用的内容(源具有示例: Haproxy的博客)
在您的情况下,只需使用
balance source
基于源(ip)的哈希:(hash-type一致< /code>确保不同的IP哈希给出相同的结果)
或基于 url参数命名
ip
:要将哈希基于多个参数,您可以:
示例来自 /a>:
You can parametrize what to use in the hash (source with examples : HaProxy's blog)
In your case, simply use
balance source
to hash based on the source (IP) :(
hash-type consistent
makes sure that distinct IP hashes give the same result)Or based on the URL parameter named
ip
:To base the hash on multiple parameters, you can :
Example from HaProxy's blog :