日期:2014-05-17  浏览次数:21011 次

Apache+Tomcat负载均衡和集群的尝试

1 各软件版本
Apache 2.2.4 因为jd_mod 用的是2.2.4的,所以这里也用这个版本,以免有问题
Tomcat 5.5.26
jd-mod: mod_jk-1.2.26-httpd-2.2.4.so

2 配置Apache

引用:

LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.4.so
JkWorkersFile D:/Apache2.2/conf/workers.properties
JkLogFile d:/Apache2.2/logs/mod_jk.log
JkLogLevel info
#JkLogLevel debug
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /servlet/* myloadbalancer
JkMount /*.jsp myloadbalancer



3 workers.properties

引用:
worker.list=myloadbalancer

worker.tomcat1.type=ajp13
worker.tomcat1.host=localhost
worker.tomcat1.port=8009
worker.tomcat1.lbfactor=1

worker.tomcat2.type=ajp13
worker.tomcat2.host=localhost
worker.tomcat2.port=9009
worker.tomcat2.lbfactor=1

worker.tomcat3.type=ajp13
worker.tomcat3.host=localhost
worker.tomcat3.port=9019
worker.tomcat3.lbfactor=1

worker.myloadbalancer.type=lb
worker.myloadbalancer.balance_workers=tomcat1,tomcat2,tomcat3
worker.myloadbalancer.sticky_session=false



使用了3个tomcat,其侦听端口分别为 8009,9009和9019
worker.myloadbalancer.sticky_session=false 声明即使是同一个SESSIONID,也不用同一个Worker进行处理,这样更有利于负载均衡。
如果为true,则如果SESSIONID相同,则会自动使用上一次对应的worker

4 apache-tomcat-5.5.26-1\conf\server.xml

查看复制到剪切板打印
  1. <Server?port="8005"?shutdown="SHUTDOWN">??
  2. .... ??
  3. <Connector?port="8080"?maxHttpHeaderSize="8192"??
  4. .... ??
  5. <Connector?port="8009"??
  6. ........ ??
  7. <Engine?name=<