Tomcat load balancer solutions

无人久伴 提交于 2019-11-29 06:59:58

If all you need is a software load balancer on linux use Apache Webserver2, Mod-Jk and Tomcat Clustering:

At your Webserver:

1) Install apache2 and modjk:

sudo apt-get install apache2 libapache2-mod-jk
sudo a2enmod jk

2) Create a "workers.properties" file available to your apache2. In some cases ist automatically created in your /etc/apache2 directory. This file is holding the lb config, node names, ips and ports of your Tomcat servers, i.e.:

worker.list=balancer,lbstats

#node1
worker.node1.type=ajp13
worker.node1.host=NODE-IP
worker.node1.port=NODE-AJP-PORT
worker.node1.lbfactor=10

#more nodes here ... (change name in between)

#lb config
worker.balancer.type=lb
#turn off sticky session
worker.balancer.sticky_session=0

#add all defined node names to this list:
worker.balancer.balance_workers=node1

#lb status information (optional)
worker.lbstats.type=status

3) Create a Mod-Jk section in your apache2 config file, if it has not been created automatically.

JkWorkersFile   /etc/apache2/workers.properties
JkLogFile       /var/log/apache2/mod_jk.log
JkShmFile       /tmp/jk-runtime-status
JkLogLevel      info

4) Mount your application to the load balancer (apache2 config file):

JkMount /MyApp       balancer
JkMount /MyApp/*     balancer

JkMount /modjkstatus lbstats

At your Tomcat servers:

5) Install tomcat using the tarball package (way better then the apt verison). Change server.xml:

  1. disable the http connectors.
  2. enable AJP/1.3 connector and set the port you defined in workers.properties for this node.
  3. add jvmRoute with the right node name to the "Engine" element:

    <Engine jvmRoute="node1" ...
    
  4. add a "Cluster" element for simplest configuration

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

6) Deploy your application to all tomcats and add a distributable element to your web.xml.

<distributable/>

7) Make sure the webserver can access the ajp ports on your tomcat servers and no one else can.

8) Start the webserver and the tomcats one after another and check the logs (/var/log/apache2/mod_jk.log, too).

9) Access your app: http://mywebserver.com/MyApp

10) Check (and deny access to) the lb status page http://mywebserver.com/modjkstatus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!