HAProxy - 基于URL的路由与负载平衡 [英] HAProxy - URL Based routing with load balancing

查看:821
本文介绍了HAProxy - 基于URL的路由与负载平衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是HAProxy的新手,我有一个关于HAProxy配置的问题,这有助于我做出正确的方法的关键决定。这将极大地帮助我决定体系结构。



我有3个应用程序。让我们说 app1 app2 app3



每个应用程序按网址区分如下:

  www.example。 com / app1 / 123  - > app1 
www.example.com/app2/123 - > app2
www.example.com/app3/123 - > app3

我计划在两个不同地区拥有每个应用程式的2个执行个体:

 区域1  -  app1,app2,app3 
区域2 - app1,app2,app3



我看到2种配置方法,但我不知道这是最好的做法:




  • 方法1 :让HAProxy1首先使用网址模式区分请求。
    HAProxy1的请求将路由到另一个HAProxy服务器,设置单个应用程序(在这种情况下为3个HAProxy服务器)以实现负载平衡。


  • 方法2 :有一个伟大的HAProxy服务器,这两个方法都如方法1中所述。也就是说,配置根据url隔离请求,然后通过每个请求通过单独的过滤器,如为每个应用程序负载平衡。




我不知道haproxy是否支持方法2。任何想法或建议非常感谢。

解决方案

您可以使用单个HAProxy服务器根据URL和负载平衡来隔离请求。
您的配置将是这样:

  frontend http 
acl app1 path_end -i / app1 / 123 #matches以/ app / 123结尾的路径
acl app2 path_end -i / app2 / 123
acl app3 path_end -i / app3 / 123


use_backend srvs_app1 if app1
use_backend srvs_app2 if app2
use_backend srvs_app3 if app3

backend srvs_app1 #backend列出您的服务器。根据您的需要使用平衡算法。
balance roundrobin
服务器host1 REGION1_HOST_FOR_APP1:PORT
服务器host2 REGION2_HOST_FOR_APP1:PORT

后端srvs_app2
余额roundrobin
服务器host1 REGION1_HOST_FOR_APP2:PORT
服务器host2 REGION2_HOST_FOR_APP2:PORT

后端srvs_app3
余额roundrobin
服务器host1 REGION1_HOST_FOR_APP3:PORT
服务器host2 REGION2_HOST_FOR_APP3:PORT

更多信息可以在首页


I am new to HAProxy and I have a question about HAProxy configuration which helps me make a key decision in taking the right approach. This will greatly help me deciding the architecture.

I have 3 apps. Let's say app1, app2, app3.

Each app is differentiated by the urls as follows:

www.example.com/app1/123 -> app1
www.example.com/app2/123 -> app2
www.example.com/app3/123 -> app3

I am planning to have 2 instances of each app in 2 different regions:

Region 1 - app1, app2, app3
Region 2 - app1, app2, app3

I see 2 methods to configure this but I am not sure which is the best practice here:

  • Method 1: Have HAProxy1 to first differentiate the requests using the url patterns. Requests from HAProxy1 will be routed to another HAProxy server set up individual apps (3 HAProxy servers in this case) for load balancing.

  • Method 2: Have one great HAProxy server which does the both as stated in method 1. That is, have configuration to segregate the requests depending on the url and then pass each request through individual filter like things set up for each app for load balancing.

I am not sure if Method 2 is supported in haproxy. Any ideas or suggested is greatly appreciated. Please put some light.

解决方案

You can segregate requests based on URL and load balance with a single HAProxy server. Your configuration will have something like this:

frontend http
acl app1 path_end -i /app1/123 #matches path ending with "/app/123"
acl app2 path_end -i /app2/123 
acl app3 path_end -i /app3/123 


use_backend srvs_app1    if app1
use_backend srvs_app2    if app2
use_backend srvs_app3    if app3

backend srvs_app1 #backend that lists your servers. Use a balancing algorithm as per your need.
   balance roundrobin 
   server host1 REGION1_HOST_FOR_APP1:PORT 
   server host2 REGION2_HOST_FOR_APP1:PORT

backend srvs_app2
   balance roundrobin
   server host1 REGION1_HOST_FOR_APP2:PORT 
   server host2 REGION2_HOST_FOR_APP2:PORT

backend srvs_app3
   balance roundrobin
   server host1 REGION1_HOST_FOR_APP3:PORT 
   server host2 REGION2_HOST_FOR_APP3:PORT

More information can be found on the homepage.

这篇关于HAProxy - 基于URL的路由与负载平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆