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

时间:2014-01-09 14:28:03

标签: apache playframework load-balancing

我使用 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/

我可以看到消息It Works from Apache ...

请帮我找一个解决方案?感谢

1 个答案:

答案 0 :(得分:2)

解析配置如下:

在httpd.conf中:

Include conf/extra/httpd-vhosts.conf

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

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

全部谢谢