Apache + Tomcat + Load Balancing

Source: Internet
Author: User

Http://www.phpchina.com/download/handbook/linux-html/1318.html

 

Continued 2: Apache 2.0.48 + Tomcat 5.0.18 + Load Balancing (Solaris 9x86)

For installation of Tomcat 5 and integration with Apache, see here.
Http://bbs.chinaunix.net/forum/6/20040214/259794.html
Http://bbs.chinaunix.net/forum/6/20040214/263220.html

I. First install the second Tomcat and copy the installed tomcat.
Code:

# Cp-RP/path/to/tomcat1/path/to/tomcat2

Ii. Set the startup script for the second Tomcat

If jsvc is used, modify the variable catalina_home to/path/to/tomcat2.
Code:

# Cd/etc/init. d
# Cp Tomcat 2
# Vi tomcat2
# CD ../rc3.d
# Ln ../init. d/tomcat2 s99tomcat2
# CD ../rc0.d
# Ln ../init. d/tomcat2 k03tomcat2

If the built-in startup. Sh is used, modify bin/Catalina. SH and add
Code:

Catalina_home =/path/to/tomcat2; export catalina_home

Iii. modify the configuration file server. xml of two Tomcat servers.

Code:

Control Port
<Server port = "8005" before modification"
Modify tomcat1 <server port = "11005"
Tomcat2 <server port = "12005" after modification"

Content to be modified ajp13 Port
<Connector Port = "8009" before modification"
Modify tomcat1 <connector Port = "11009"
Tomcat2 <connector Port = "12009" after modification"

Http port
<Connector Port = "8080" before modification"
Modify tomcat1 <connector Port = "11080"
Tomcat2 <connector Port = "12080" after modification"

Set jvmroute
<Engine name = "Catalina" defaulthost = "localhost" DEBUG = 0 ">
After modification, export AT1 <engine jvmroute = "tomcat1" name = "Catalina" defaulthost = "localhost" DEBUG = 0 ">
After modification, Tomcat 2 <engine jvmroute = "tomcat2" name = "Catalina" defaulthost = "localhost" DEBUG = 0 ">

Iv. Configure workers2.proerties

Code:

# ---- Worker2.properties

[Logger. apache2]
Level = debug

# Shared memory handling. needs to be set.
[SHM]
File =/var/Apache/logs/SHM. File
Size = 1048576

[Channel. Socket: localhost: 11009]
Tomcatid = localhost: 11009
Port = 11009
Host = 127.0.0.1
Lb_factor = 1
Group = lb_1
Disabled = 0

[Channel. Socket: localhost: 12009]
Tomcatid = localhost: 12009
Port = 12009
Host = 127.0.0.1
Lb_factor = 1
Group = lb_1
Disabled = 0

[Status: Status]

[LB: LB]
Info = default Load balancer
DEBUG = 1

[LB: lb_1]
Info = Second Load balancer
DEBUG = 0

# URI Mapping

[URI:/jkstatus/*]
Group = Status: Status

[URI:/*]
Group = LB: lb_1

# ---- End of workers2.properties

V. Create two JSP files for testing
/Path/to/tomcat1/webapps/root/test. jsp
Code:

<HTML>
Body bgcolor = "red"
<Center>
<% = Request. getsession (). GETID () %>
<H1> Tomcat 1 </Body>
</Html>

/Path/to/tomcat2/webapps/root/test. jsp
Code:

<HTML>
Body bgcolor = "blue"
<Center>
<% = Request. getsession (). GETID () %>
<H1> Tomcat 2 </Body>
</Html>

Vi. Test
Start tomcat1, tomcat2, and Apache
Code:

#/Etc/init. d/tomcat start
#/Etc/init. d/tomcat2 start
#/Etc/init. d/Apache start

Test http: // yourserverip/test. jsp in a browser.
The red page indicates that the access is directed to tomcat1.
The blue is tomcat2

VII. Links
Http://raibledesigns.com/tomcat/

Implement session replication

I. Modify server. xml
Cancel the comments of the following code in the server. xml file, and modify the value of tcplistenport. Note that no conflict exists. You can set it to 4001 or 4002.
Code:

<Cluster classname = "org. Apache. Catalina. Cluster. tcp. simpletcpcluster"
Managerclassname = "org. Apache. Catalina. Cluster. session. deltamanager"
Expiresessionsonshutdown = "false"
Usedirtyflag = "true">

<Membership
Classname = "org. Apache. Catalina. Cluster. MCAST. mcastservice"
Mcastaddr = "228.0.0.4"
Mcastport = "45564"
Mcastfrequency = "500"
Mcastdroptime = "3000"/>

<Cycler
Classname = "org. Apache. Catalina. Cluster. tcp. replicationlistener"
Tcplistenaddress = "Auto"
Tcplistenport = "4001"
Tcpselectortimeout = "100"
Tcpthreadcount = "6"/>

<Sender
Classname = "org. Apache. Catalina. Cluster. tcp. replicationtransmitter"
Replicationmode = "pooled"/>

<Valve classname = "org. Apache. Catalina. Cluster. tcp. replicationvalve"
Filter = ". *. gif;. *. js;. *. jpg;. *. HTM;. *. html;. *. txt;"/>
</Cluster>

Ii. modify web. xml
Modify the Web. xml file of the Web application that demonstrates Servlet and add the <distributable/> element.
Code:

......

<Display-Name> servlet 2.4 examples </display-Name>
<Description>
Servlet 2.4 examples.
</Description>

<Distributable/>

......

Iii. Test

Access URL: http: // serverip/Servlets-examples/servlet/sessionexample

1. Disable Tomcat 1 and tomcat 2;
2. Start tomcat1
3. Enter the tomcat1 attribute name and tomcat1 attribute value in the browser and submit again. The returned page shows that the session contains the tomcat1 attribute just entered;
4. start Tomcat 2;
5. After a while (wait for tomcat2 to communicate with tomcat1 and copy the information), disable tomcat1;
6. Enter the property name tomcat2 and property value tomcat2 in the browser and submit it again. The returned page shows that the session contains the tomcat2 property just entered and the tomcat1 property previously entered;
7. Start tomcat1;
8. After a while (wait for tomcat2 to communicate with tomcat1 and copy the information), disable tomcat2;
9. Enter the tomcat11 attribute name and tomcat11 attribute value in the browser and submit it again. The returned page shows that the session contains the tomcat11 attribute just entered, as well as the tomcat1 and tomcat2 attributes previously entered;

Iv. References

Http://jakarta.apache.org/tomcat/tomcat-5.0-doc/cluster-howto.html
Http://www-900.ibm.com/developerWorks/cn/java/l-jetspeed/

End of Full Text

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.