日期:2014-05-16  浏览次数:21081 次

Apache2.2+Tomcat6配置集群、负载均衡、session

终于搞定的;

本文参照http://lxiaodao.iteye.com/blog/321000来修改的.

详细的配置过程,我把配置过程中几个不同和关键的地方重点提出来。
软件版本有所不同,罗列如下:
Apache? :apache_2.2.4-win32-x86-no_ssl.msi 1个
Tomcat:? apache-tomcat-6.0.29-windows-x86.zip ? 2个
mod_jk: mod_jk-1.2.26-httpd-2.2.4.so 1个?
? 我在一台机器(xp)上进行测试。
把apache和tomcat安装好以后,配置过程中有如下一些地方改动或者改进。

在mod_jk-1.2.26-httpd-2.2.4.so复制到Module目录下

在D:\Apache2.2\conf\httpd.conf增加

# JK module settings Include conf/mod_jk.conf

?

?

?


?在conf目录新增mod_jk.conf ,内容如下

# Load JK Module LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.4.so # Configure mod_jk JkWorkersFile conf/workers.properties JkMountFile conf/uriworkermap.properties JkShmFile logs/mod_jk.shm JkLogFile logs/mod_jk.log JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories JkLogLevel warn JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" HostnameLookups Off <Location /jkmanager/> JkMount jkstatus Order deny,allow Deny from all Allow from 127.0.0.1 </Location>

?

?

?


?分别在Module目录下:workers.properties文件

# environment slash for Windows ps=\ worker.retries=2 worker.list=loadbalancer,jkstatus worker.s1.type=ajp13 worker.s1.host=localhost worker.s1.port=11009 worker.s1.lbfactor=1 worker.s1.connection_pool_timeout=600 worker.s1.socket_keepalive=true worker.s1.socket_timeout=60 worker.s2.type=ajp13 worker.s2.host=localhost worker.s2.port=12009 worker.s2.lbfactor=1 worker.s2.connection_pool_timeout=600 worker.s2.socket_keepalive=true worker.s2.socket_timeout=60 worker.jkstatus.type=status worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=s1,s2 worker.loadbalancer.sticky_session=true

?

?

?


?uriworkermap.properties文件

/*.jsp=loadbalancer /*.action=loadbalancer /jkmanager/*=jkstatus !*.gif=loadbalancer !*.jpg=loadbalancer !*.png=loadbalancer !*.bmp=loadbalancer !*.css=loadbalancer !*.js=loadbalancer !*.htm=loadbalancer !*.html=loadbalancer !*.swf=loadbalancer

?

?

?


?然后配置tomcat6.0修改server.xml

?

<Server port="12005" shutdown="SHUTDOWN">

? <!--APR library loader. Documentation at /docs/apr.html -->
? <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
? <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
? <Listener className="org.apache.catalina.core.JasperListener" />
? <!-- Prevent memory leaks due to use of particular java/javax APIs-->
? <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
? <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
? <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
? <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

? <!-- Global JNDI resources
?????? Documentation at /docs/jndi-resources-howto.html
? -->
? <GlobalNamingResources>
??? <!-- Editable user database that can also be used by
???????? UserDatabaseRealm to authenticate users
??? -->
??? <Resource name="UserDatabase" auth="Container"
????????????? type="org.apache.catalina.UserDatabase"
????????????? description="User database that can be updated and saved"
????????????? factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
????????????? pathname="conf/tomcat-users.xml" />
? </GlobalNamingResources>

? <!-- A "Service" is a collection of one or more "Connectors" that share
?????? a single "Container" Note:? A "Service" is not itself a "Container",
?????? so you may not define subcomponents such as "Valves" at this level.
?????? Documentation at /docs/config/se