Apache2.4 + Tomcat6集群配置笔记
一、安装Apache
1、修改httpd.conf中的路径c:/Apache24为Apache安装包的路径,如:D:/httpd-2.4.12/Apache24
2、进入Apache安装目录下的bin目录:
httpd.exe -k install
3、 启动服务 httpd.exe -w -n "Apache2.4" -k start
(卸载服务sc delete Apache2.4)
二、配置Apache
1、打开conf/httpd.conf文件,加载以下模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule rewrite_module modules/mod_rewrite.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
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule speling_module modules/mod_speling.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
2、去掉 Include conf/extra/httpd-vhosts.conf 前面的注释符
3、在文件末尾添加反向代理
ProxyRequests Off
<proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:11007 loadfactor=1 route=tomcat1
BalancerMember ajp://127.0.0.1:11008 loadfactor=1 route=tomcat2
BalancerMember ajp://127.0.0.1:11009 loadfactor=1 route=tomcat3
</proxy>
4、打开conf/extra/httpd-vhosts.conf文件,配置虚拟站点
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName localhost
ServerAlias localhost
ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://cluster/
ErrorLog "logs/lbtest-error.log"
CustomLog "logs/lbtest-access.log" common
</VirtualHost>
三、配置tomcat
1、复制3个tomcat
2、修改tomcat2 的server.xml
<Server port="8005" shutdown="SHUTDOWN">把port改为8006
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>把port改为8090
<Connector port="11008" protocol="AJP/1.3" redirectPort="8443"/>把port改为11008
<Engine defaultHost="localhost" name="Catalina" >添加jvmRoute="tomcat2",在tomcat1中同样添加jvmRoute="tomcat1"
打开<Cluster classname="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>注释
3、修改tomcat3 的server.xml,同tomcat2,把port改为11009,添加jvmRoute="tomcat3",保证3个tomcat的端口都不相同,并且AJP的的端口和httpd.conf文件中配置的代理端口一致。
四、在项目中的web.xml文件的<web-app>节点下加入<distributable />