0、下载对应文件,注意mod_jk与apache版本的对应,然后安装
httpd-2.2.20
apache-tomcat-6.0.33
tomcat-connectors-1.2.32
1、将mod_jk.so放入apache/modules
1)、过程略
2、在apache/conf下新建mod_jk.conf文件,文件内容如下:
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn
JkMount /* controller
3、在apache/conf下新建workers.properties文件,文件内容如下:
worker.list = controller,tomcat1,tomcat2
worker.tomcat1.port=8001
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1
worker.tomcat2.port=8002
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2
worker.controller.sticky_session=false
4、在apache/conf下新建uriworkermap.properties文件,注意controller接受和不接受的后缀,文件内容如下:
/*=controller
/*.jsp=controller
/*.do=controller
/*.servlet=controller
!/*.gif=controller
!/*.jpg=controller
!/*.png=controller
!/*.css=controller
!/*.js=controller
!/*.htm=controller
!/*.html=controller
5、修改tomcat/conf/server.xml文件,替换原<Engine name="Catalina" defaultHost="localhost"/>,每个tomcat都需要修改,注意jvmRoute参数和Receiver的端口的修改。
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.BackupManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"
mapSendOptions="6"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
bind="127.0.0.1"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
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;"/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
6、修改端口,一共3处,以下为第一个端口,以后每增一个tomcat,端口+1配置
1)、<Server port="8005" shutdown="SHUTDOWN"> 修改为<Server port="8051" shutdown="SHUTDOWN">
2)、<Connector port="8080" protocol="HTTP/1.1" 修改为<Connector port="8801" protocol="HTTP/1.1"
3)、<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 修改为<Connector port="8001" protocol="AJP/1.3" redirectPort="8443" />
7、修改apache/conf/httpd.conf文件,在最后添加
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn
JkMount /* controller
8、修改apache/conf/httpd.conf文件,如果ServerName被注释掉,去掉注释,并修改为:ip或域名或127.0.0.1后加端口,类似:127.0.0.1:80
9、修改每个tomcat下项目中的web.xml文件,增加<distributable/>标签。[注:告诉此应用为分布式]
10、测试index.jsp,在浏览器中输入:http://localhost/index.jsp,每刷新一下,可以看到2个tomcat被轮询访问,如果没有或只有一个,说明配置错误
请查看以下配置:
1)、2个tomcat是否都启动。
2)、2个tomct是否存在端口冲突。[3个端口]
3)、2个tomcat的jvmRoute配置正确
4)、apache是否正常配置。
5)、mod_jk文件是否拷贝
index.jsp内容:
<%
out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");
out.println("<br> ID " + session.getId()+"<br>");
%>