版本:
httpd-2.2.22-win32-x86-openssl-0.9.8t.msi
apache-tomcat-7.0.27-windows-x64.zip
windows7 64bit
实例名称 |
修改的文件 |
Tcp端口(shutdown,AJP Connector) |
jvmRoute属性值 |
TCP端口 |
Machine1 |
\cluster\machine1\conf\server.xml |
8015,8019 |
Machine1 |
5019 |
Machine2 |
\cluster\machine2\conf\server.xml |
8025,8029 |
Machine2 |
5029 |
Machine3 |
\cluster\machine3\conf\server.xml |
8035,8039 |
Machine3 |
5039 |
此处选择的设置确保在同一物理机器上同时启动3个实例不会冲突。如果实际在网络中的3个物理机器上进行测试,它们可以都使用表中的Machine1.。
Server.xml Cluster节点配置如下:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="6">
<!--
<Manager className="org.apache.catalina.ha.session.BackupManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"
mapSendOptions="6"/>
-->
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
bind="192.168.1.104"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="5019"
selectorTimeout="100"
maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
加粗的标识根据实际需要变更。
Apache修改的地方
Conf\httpd.conf
启用以下模块:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
启用:
Include conf/extra/httpd-vhosts.conf
修改conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.cliff.com.cn
DocumentRoot "C:/Install/Apache2.2/docs/dummy-host.cliff.com.cn"
ServerName dummy-host.cliff.com.cn
ServerAlias www.dummy-host.cliff.com.cn
ProxyPass / balancer://cluster/ stickysession=jessionid nofailover=On
ProxyPassReverse / balancer://cluster
ProxyRequests Off
ProxyPreserveHost On
ErrorLog "logs/dummy-host.cliff.com.cn-error.log"
CustomLog "logs/dummy-host.cliff.com.cn-access.log" common
</VirtualHost>
ProxyRequests Off
<proxy balancer://cluster>
BalancerMember ajp://192.168.1.104:8019 loadfactor=1 route=Machine1
BalancerMember ajp://192.168.1.104:8029 loadfactor=1 route=Machine2
BalancerMember ajp://192.168.1.104:8039 loadfactor=1 route=Machine3
</proxy>
每个需要集群应用的web.xml 中加入以下配置:
<distributable/>
创建测试 session.jsp内容如下:
<%
//HttpSession session = request.getSession(true);
System.out.println(session.getId());
out.println("<br> SESSION ID:" + session.getId()+"<br>");
%>
访问session.jsp查看.