Apache Tomcat Load Balancing Integration

Source: Internet
Author: User
Tags tomcat server apache tomcat

The first time to integrate Apache, Tomcat, a lot of information on the network, and then according to the data configuration

Environment Description:

Two window2003 servers

Httpd-2.2.15-win32-x86

jakarta-tomcat-5.0.28

Mod_jk-1.2.27-httpd-2.2.10.so

At the back of the Apache httpd.conf file, add include conf/mod_jk.conf

Create a new mod_jk.conf file in the same directory as httpd.conf:

### load mod_jk module LoadModule jk_module modules/mod_jk-1.2.27-httpd-2.2.10.so ### configuration mod_jk jkworkersfile Erties #加载workers的请求处理分配文件 #JkMountFile conf/uriworkermap.properties #指定jk的日志输出文件 jklogfile logs/mod_jk.log #指定日志级别 Jkloglevel info #日志记录的格式 jklogstampformat "[%a%b%d%h:%m:%s%Y]" # Request distribution configuration, you can configure multiple #JkMount/*.jsp Controller #JkMount/* . shtml Controller Jkmount/* Controller # Turn off host lookup, if on, it affects performance and can have a delay of more than 10 seconds. Hostnamelookups off

Create a new workers.properties file in the same directory as httpd.conf:

# worker List Worker.list=controller,s1,s2 #第一个server的配置, server named S1 #ajp13 port number, server.xml configuration under Tomcat, default 8009 worker.s1.port=8009 #tomcat的主机地址, if not for this machine, please fill in the IP address worker.s1.host=192.168.0.109 worker.s1.type=ajp13 #server的加权比重, the higher the value, The more requests are worker.s1.lbfactor=1 #第二个server的配置, the server name is S2 worker.s2.port=8009 worker.s2.host=192.168.50.129 Worker.s2.type=ajp13 worker.s2.lbfactor=1 #重试次数 worker.retries=3 #========controller, load Balancing controller ======== WORKER.CONTROLLER.TYPE=LB #指定分担请求的tomcat worker.controller.balanced_workers=s1,s2 #设置用于负载均衡的server的session可否共享 Most of the online articles are said to be set to 1 #也有网友说自己设置为1死活就是不能自动分配服务, set to 0 can #worker. controller.sticky_session=0 worker.controller.sticky_ Session=1 #我配置为1时, the same session will only visit one Tomcat to turn off the browser and reopen it before accessing another Tomcat #worker. controller.sticky_session= False controls whether the session is sticky, #如果设置为true, the session is sticky, the same request will be processed on the same tomcat, generally set to false; #worker. controller.sticky_session= False

The next step is to modify Tomcat

Modify Server.xml

Add localhost "jvmroute=" to the <engine name= "Catalina" defaulthost= "S1" on a tomcat

Become <engine name= "Catalina" defaulthost= "localhost" jvmroute= "S1" >

Another tomcat for <engine name= "Catalina" defaulthost= "localhost" jvmroute= "s2" >

Then remove the <cluster annotation and realize resource sharing

This is not enough to add <distributable/> to the project's Web.xml

<web-app xmlns= "Http://java.sun.com/xml/ns/j2ee" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version= "2.4" > <display-name>welcome to tomcat</display-name> <description>welcome to Tomcat</description > <distributable/>

This enables Apache Tomcat to achieve load balancing integration.

The above is according to the data on the network deployment, the test found that the only thing Apache do is to receive all requests, and then to Tomcat processing, so that the Apache to deal with the static page's ability.

After the study, the above configuration is modified as follows

Modify the mod_jk.conf file,

Comment out Jkmount/* Controller and change to

#按照自己的项目情况

Jkmount/*.jsp Controller
Jkmount/*.shtml Controller

Then restart the operation of the project, found that the JSP page pictures are not shown, that the static page elements Apache processing, the reason the picture does not show, because we did not give Apache specify the project directory

modifying httpd.conf files

Change the DocumentRoot "D:/apache2.2/htdocs" to the path of the project DocumentRoot "D:/cms"

and <directory "D:/apache2.2/htdocs" > also need to be modified

If you don't want Apache to list file lists

The options Indexes followsymlinks Indexes removed, for options FollowSymLinks

Finished, and then tested, the release page appears garbled, Tomcat Server.xml and Apache connectors on the code

<connector port= "8009" enablelookups= "false" edirectport= "8443" debug= "0" protocol= "ajp/1.3" uriencoding= "Utf-8"/ >

Re-test, there is no further problems.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.