设置 2 个 Play 框架实例的负载均衡器



我用 PLAY Framework 2.2.1 创建了一个应用程序(名称:osc_poc),并将源文件夹复制到另一个目标以创建该应用程序的第二个实例。

我使用两个具有不同端口的终端启动应用程序:

play            -> to launch the play console in each terminal
run 9850        -> to deploy the first app with port 9850 in terminal 1
run 9851        -> to deploy the second app with port 9851 in terminal 2

然后我安装了Apache HTTPD服务器2.2.25,配置如下:

在 httpd.conf 中:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so

在httpd-vhosts.conf中:

<VirtualHost osf_poc.com:80>
  ServerName osf_poc.com
  <Location /balancer-manager>
    SetHandler balancer-manager
    Order Deny,Allow
    Deny from all
    Allow from .osf_poc.com
  </Location>
  <Proxy balancer://mycluster>
    BalancerMember http://localhost:9850
    BalancerMember http://localhost:9851 status=+H
  </Proxy>
  <Proxy *>
    Order Allow,Deny
    Allow From All
  </Proxy>
  ProxyPreserveHost On
  ProxyPass /balancer-manager !
  ProxyPass / balancer://mycluster/
  ProxyPassReverse / http://localhost:9850/
  ProxyPassReverse / http://localhost:9851/
</VirtualHost

而且我不知道要启动什么才能转到负载均衡器 ip...

如果我去:

http://localhost:9850/

我可以看到第一个应用程序

如果我去:

http://localhost/

我可以看到来自 Apache 的消息它有效...

请你能帮我找到解决方案吗?谢谢

SOLVE SOLVE配置如下:

在 httpd.conf 中:

Include conf/extra/httpd-vhosts.conf

在 httpd-vhosts.conf 中(作为第一个 VirtualHost 块):

<VirtualHost *:80>
  ServerName osf_poc.com
  <Location /balancer-manager>
    SetHandler balancer-manager
    Order Deny,Allow
    Deny from all
    Allow from .osf_poc.com
  </Location>
  <Proxy balancer://mycluster>
    BalancerMember http://localhost:9850
    BalancerMember http://localhost:9851 status=+H
  </Proxy>
  <Proxy *>
    Order Allow,Deny
    Allow From All
  </Proxy>
  ProxyPreserveHost On
  ProxyPass /balancer-manager !
  ProxyPass / balancer://mycluster/
  ProxyPassReverse / http://localhost:9850/
  ProxyPassReverse / http://localhost:9851/
</VirtualHost

只需要启动http://localhost/就可以平衡!

不知道以下代码是否必要:

ServerName osf_poc.com
  <Location /balancer-manager>
    SetHandler balancer-manager
    Order Deny,Allow
    Deny from all
    Allow from .osf_poc.com
  </Location>

谢谢大家

最新更新