在wls中,集群的受管服务器无需使用相同的端口,这使在一个主机上实现集群成为可能。下面的例子是在一个主机(172.30.94.60)上的 wls7里创建一个集群(mycluster)DEMO,包括管理服务器(myserver:7001)、集群(两个受管服务器serverA: 8001、serverB:8003)、代理服务器(ProxyServer:80)。应用WebApp是部署在集群上的web应用,而 DefaultWebApp是部署在代理服务器上用来代理集群应用WebApp的。具体步骤如下:
1.创建集群域clusterdomainnew,管理服务器myserver(7001:7003);
2.创建Machine:admin(myserver,ProxyServer),cluster(serverA,serverB);
3.创建受管服务器serverA(8001),serverB(8003);
4.创建集群mycluster;
Choose Servers for this Cluster: serverA,serverB
config.xml:
<Cluster ClusterAddress="172.30.94.60:8001,172.30.94.60:8003"
MulticastAddress="237.0.0.1" MulticastPort="7777" Name="mycluster"/>
5.部署WebApp应用,targets mucluster;
6.创建代理服务器ProxyServer(80),将DefaultWebApp targets ProxyServer;
7.编辑DefaultWebApp应用,注册HttpClusterServlet:
<servlet>
<servlet-name>HttpClusterServlet</servlet-name>
<servlet-class> WebLogic.servlet.proxy.HttpClusterServlet</servlet-class>
<init-param>
<param-name>WebLogicCluster</param-name>
<param-value>172.30.94.60:8001:8002|172.30.94.60:8003:8004</param-value>
</init-param>
<init-param>
<param-name>DebugConfigInfo</param-name>
<param-value>ON</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HttpClusterServlet</servlet-name>
<url-pattern>/</url-pattern></servlet-mapping>
<servlet-mapping>
<servlet-name>HttpClusterServlet</servlet-name>
<url-pattern>*.jsp</url-pattern> </servlet-mapping>
<servlet-mapping>
<servlet-name>HttpClusterServlet</servlet-name>
<url-pattern>*.htm</url-pattern> </servlet-mapping>
<servlet-mapping>
<servlet-name>HttpClusterServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
8.重启myserver;
9.启动serverA:startManagedWeblogic serverA http://172.30.94.60:7001;
启动成功后,访问 http://172.30.94.60:8001/WebApp/ 验证一下!
10.启动serverB:startManagedWeblogic serverB http://172.30.94.60:7001;
启动成功后,访问 http://172.30.94.60:8003/WebApp/ 验证一下!
11. 启动ProxyServer:startManagedWeblogic ProxyServer http://172.30.94.60:7001。
访问 http://172.30.94.60/WebApp,是不是大功告成了:)