tomcat6 + apache2 集群配置
参考
http://www.iteye.com/topic/622068
1 安装apache2.2
2 装2台tomcat(本机ip:192.168.190.241)(另台192.168.190.200)
3 配置apache文件
3.1
下载(jk,一定要与apache的版本一致, 查看apache版本号命令:httpd.exe -v)
http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/
把mod_jk-1.2.27-httpd-2.2.10.so 放在apache\modules\下
3.2 配置conf/httpd.conf文件
LoadModule jk_module modules/mod_jk-1.2.27-httpd-2.2.10.so #加载这个模块
JkWorkersFile conf/works.properties #加载tomcat配置文件
JkLogFile logs/mod_jk.log#日志加载文件
JkMount /* controller #此处是指定分配给tomcat的请求 例如*.do *.jsp
说明controller是在works.properties的对应配置
如果是转发所有jsp文件
JkMount /*.jsp controller
如果是在tomcat/webapps/部署个project,例如 webapps/car-manager
希望输入http://localhost/car-manager由apache转发到tomcat处理
//
JkMount /car-manager/* controller #可以这样配置路径转发
在conf文件下, 建立works.properties文件,内容如下
worker.list = controller,tomcat1,tomcat2 #server 列表
#========tomcat1========
worker.tomcat1.port=8009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 2 #server的加权比重,值越高,分得的请求越多
#========tomcat2========
worker.tomcat2.port=9009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=192.168.190.200 #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 3 #server的加权比重,值越高,分得的请求越多
#负载均衡分发控制器
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat
worker.controller.sticky_session=True
4 tomcat配置ajp13端口
在 本地/tomcat/conf/server.xml
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> # 8009要与apache/works.properties 配置一致
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1"> # tomcat1要与apache/works.properties 配置一致
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
配置192.168.190.200/tomcat/conf/server.xml
<Connector port="9009" protocol="AJP/1.3" redirectPort="8443" /> # 9009要与apache/works.properties 配置一致
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2"> # tomcat2要与apache/works.properties 配置一致
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
5 如果需要session复制
需要另外配置