spring 启动应用程序负载与 apache 平衡

spring boot application load balanced with apache

我有一个包含多个模块的应用程序

Web 浏览器仅与 apache 服务器通信,后者将请求路由到这些应用程序(使用虚拟主机和重定向)。

For more clarity, here's a graphic explanation of this distribution

这是后端的虚拟主机配置

<VirtualHost *:80> 
  ServerName api.myapp.com
  ProxyPreserveHost On
  ProxyRequests Off
  ProxyPass / http://localhost:8080/
  ProxyPassReverse / http://localhost:8080/
</VirtualHost> 

我需要为后端应用程序实施 HA 保持 软件实例(即,我无法添加新的 apache 专用实例平衡)。

我不知道该怎么做,我读过的教程解释了如何将整个 apache 实例转换为负载均衡器,但我只需要将 HA 带到一个虚拟主机(后端服务)来保留软件实例就像现在一样。

如有任何帮助,我将不胜感激。

谢谢

此致

Httpd 文档乍一看非常混乱,它没有合并概念,例如虚拟主机与平衡器。但我仍然从他们的 docs.

中提取了很多信息

一种基本方法是设置一个平衡器及其成员,然后将所有内容代理给它。

为此,我们需要安装一些模块:sudo a2enmod proxy proxy_http proxy_balancer lbmethod_byrequests 必须足够,否则,请检查日志中是否缺少模块或建议。

然后,填补虚拟主机中的空白:

<VirtualHost *:80>
        ServerName api.myapp.com
        ProxyPreserveHost On
        ProxyRequests Off
        #Your balanced backends
        <Proxy balancer://backend-cluster>
                BalancerMember http://localhost:3000
                BalancerMember http://localhost:9000
                ProxySet lbmethod=byrequests
        </Proxy>
        #Balancer admin interface for localhost access
        <Location /balancer-manager>
                SetHandler balancer-manager
                Order allow,deny
                allow from localhost 
        </Location>

        ProxyPass /balancer-manager !
        #Proxying everything to your backends
        ProxyPass / balancer://backend-cluster/

</VirtualHost>

Httpd 还提供了一些其他算法来平衡您的请求。如您所见,提供的示例与 byrequest 保持平衡(简而言之,在成员之间共享请求)。剩下的是(我鼓励你阅读文档):

  • bytraffic - 按每个成员的流量分担负载
  • bybusyness - 选择工作数量较少的成员
  • heartbeat - 使用mod_heartbeat来平衡工作

这个最小配置必须足以实现最小的 HA 后端服务。