切换到幻灯片模式
需要配置前端web层和后端应用层:
1.web层配置:
<!--
- Configuration
for the web-tier/load-balancer
-->
<cluster id=
"web-tier">
<server-default>
<!-- The http port -->
<http address=
"*" port=
"80"/>
</server-default>
<server id=
"web-a" address=
"127.0.0.1" port=
"6700"/>
<cache path=
"cache" memory-size=
"64M"/>
<host id=
"">
<web-app id=
"/">
<rewrite-dispatch>
<load-balance regexp=
"" cluster=
"app-tier"/>
</rewrite-dispatch>
</web-app>
</host>
</cluster>
<cluster id=
"app-tier">
<server id=
"a" address=
"127.0.0.1" port=
"6800"/>
<server id=
"b" address=
"127.0.0.1" port=
"6801"/>
<persistent-store type=
"cluster">
<init path=
"cluster"/>
</persistent-store>
<web-app-default>
<session-config>
<use-persistent-store/>
</session-config>
</web-app-default>
<host id=
"">
...
</host>
</cluster>
以上配置将来自80的请求分发给app-tier应用层集群处理。
2.应用层集群配置:
<!-- define the servers in the cluster -->
<server id="a" address="127.0.0.1" port="6800"/>
<server id="b" address="127.0.0.1" port="6801"/>
3.启动应用层服务器:
D:\resin-pro-3.1.3\httpd.exe -conf conf/resin1.conf -server a
D:\resin-pro-3.1.3\httpd.exe -conf conf/resin1.conf -server b
以上启动了两个应用服务器a和b.
4.启动前端WEB服务器:
1
|
> D:\resin-pro-3.1.3\httpd.exe -conf conf/resin-web.conf -server web-a
|
5.写测试JSP a.jsp:
1
|
<%System.out.println("aaaaaaaaaaaa");%>
|
6.在浏览器中访问:
http://localhost/a.jsp
观察一下控制台,会在两个窗口控制台轮流打印出 aaaaaaaaaaaa,说明负载均衡Servlet工作正常。
关掉一个应用服务器,再次访问,会发现访问正常。