服务器之家

专注于服务器技术!
当前位置:首页 > Web服务器 > Apache

Apache+tomcat集群的整合配置

发布时间:2014-04-23 来源:服务器之家

用mod_jk来做一个双tomcat的集群加session保持就可以
tar zxvf tomcat-connectors-1.2.28-src.tar.gz
cd tomcat-connectors-1.2.28-src/native
./configure --with-apxs=/usr/local/apache/bin/apxs --with-java-home=/usr/local/jdk
make ; make install

在/usr/local/apache/modules/ 下会产生mod_jk.so文件,然后修改apache配置文件:
vi /usr/local/apache/conf/httpd.conf
------------------------------------------------------------------------------------------------
LoadModule jk_module modules/mod_jk.so

JkWorkersFile conf/workers.properties
JkShmFile logs/mod_jk.shm
JkLogFile logs/mod_jk.log
JkLogLevel info
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkMount /* controller
JkUnMount /*.htm controller
jkUnMount /*.html controller
------------------------------------------------------------------------------------------------
更改DocumentRoot 为tomcat的部署目录

建立JK配置文件:
vi /usr/local/apache/conf/workers.properties
------------------------------------------------------------------------------------------------
workers.java_home=/usr/local/jdk
ps=/
worker.list=controller
worker.tomcat1.port=端口号
worker.tomcat1.host=IP地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1

worker.tomcat2.port=端口号
worker.tomcat2.host=IP地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1

worker.controller.type=lb
worker.controller.balance_workers=tomcat1,tomcat2
worker.controller.sticky_session=1

------------------------------------------------------------------------------------------------
修改web应用里面WEB-INF目录下的web.xml文件,加入标签
<distributable/>
直接加在</web-app>之前就可以了
做tomcat集群必须需要这一步,否则用户的session就无法正常使用。