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

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

问题描述

我是 HAProxy 新手,我有一个关于 HAProxy 配置的问题,这有助于我在采取正确方法时做出关键决定.这将极大地帮助我决定架构.

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.

我有 3 个应用程序.比如说 app1app2app3.

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

我计划在 2 个不同的地区为每个应用创建 2 个实例:

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

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

我看到了 2 种配置方法,但我不确定哪种方法是最佳实践:

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

  • 方法 1:让 HAProxy1 首先使用 url 模式区分请求.来自 HAProxy1 的请求将被路由到另一个设置单个应用程序的 HAProxy 服务器(在本例中为 3 个 HAProxy 服务器)以进行负载平衡.

  • 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.

方法 2:拥有一台出色的 HAProxy 服务器,可以按照方法 1 中的说明进行这两种操作.也就是说,配置根据 url 隔离请求,然后通过每个请求单个过滤器,例如为每个应用设置的负载平衡.

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.

我不确定 haproxy 是否支持方法 2.非常感谢任何想法或建议.请放点光.

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

推荐答案

您可以基于 URL 隔离请求并使用单个 HAProxy 服务器进行负载平衡.您的配置将是这样的:

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天全站免登陆