1.Apache的conf/httpd.conf尾部添加:
# 加载 mod_jk 模块
LoadModule jk_module modules/mod_jk.so
#
# Configure mod_jk
#
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn
2.uriworkermap.properties内容:
/*=lbworker
/jkstatus=status
!/*.gif=lbworker
!/*.jpg=lbworker
!/*.png=lbworker
!/*.css=lbworker
!/*.js=lbworker
!/*.htm=lbworker
!/*.html=lbworker
3.workers.properties内容:
# list the workers by name
worker.list=lbworker, status
# localhost server 1
# ------------------------
worker.worker2.port=9009
worker.worker2.host=localhost
worker.worker2.type=ajp13
worker.worker2.lbfactor=1
# localhost server 2
# ------------------------
worker.worker3.port=9010
worker.worker3.host=localhost
worker.worker3.type=ajp13
worker.worker3.lbfactor=1
#设置均衡策略
worker.lbworker.type=lb
worker.lbworker.balance_workers=worker2,worker3 #这里在的worker2、worker3为需要与tomcat设置的别名一致
worker.lbworker.sticky_session=1
worker.status.type=status
worker.retries=3
4.tomcat修改:
(1)worker2
<Connector port="9090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker2">
......
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
......
</Engine>
(2)worker3
<Connector port="9091" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker3">
......
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
......
</Engine>