apache jk_mod和tomcat集群做负载均衡简单配置

时间:2020-11-25 16:53:10

刚初步了解了apache的配置,试着用apache和tomcat集群来做负载均衡,记录如下以备参考


一, 用mod_jk来做负载均衡,mod_proxy等模块来实现负载均衡后面再尝试,apache这一边(也就是load balancer)的配置如下

1. apache主配置文件httpd.conf中加入下一行

Include conf/jk-mod.conf


2. 在apache的conf目录下建立jk-mod.conf,内容如下

JkWorkersFile conf/workers.properties

JkLogFile logs/mod_jk.log

JkLogLevel debug
JkMount /* loadbalancer


3. 在apache的conf目录下建立workers.properties,内容如下

worker.list=loadbalancer

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

worker.tomcat2.port=8010
worker.tomcat2.host=192.168.1.114
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=False


至此部,负载均衡这一端就简单配置完了,下面来配置tomcat集群这一端

二,tomcat集群构建

1. download tomcat 7 and unpack it to disk with 2 copies, rename to tomcat1, tomcat2(another solution is to launch two different instances based on one copy with different CATALINA_BASE, but it need more steps, for simplicity, I just use 2 different copies)

2. uncomment following lines in server.xml in both copies

      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

3. add <distributable/> to web.xml of the app you deployed in both tomcat servers.


4. modify the port in server.xml of tomcat2, including the http connector port, the ajp connector port, the shutdown port and the redirectPort.


ok,至此tomcat集群构建完毕