Apache configured as a load balancer for the Tomcat cluster

Source: Internet
Author: User
Tags tomcat

1) Open the "httpd.conf" file in the "/usr/local/apache2/conf" directory and add the following configuration item at the end of the file, as shown in Figure 4-2-1.

Proxyrequests OFF

proxypass/balancer://mycluster/

<proxy balancer://mycluster/>

Balancermember ajp://localhost:10009 ROUTE=TOMCAT1

Balancermember ajp://localhost:20009 ROUTE=TOMCAT2

</proxy

Figure 4-2-1

Description: Where "Mycluster" is the name of the cluster, "ajp://localhost:10009 ROUTE=TOMCAT1" corresponds to the Tc6_a instance in the Tomcat cluster, "ajp://localhost:20009 Route=tom Cat2 "corresponds to the Tc6_b instance in the Tomcat cluster. With this configuration, Apache can become the load balancer for the Tomcat cluster that was built earlier.

(2) After the modification is complete, save the "httpd.conf" file.

(3) Type the following command in the terminal to launch the "Tc6_a" Tomcat instance.

Cd/tc6_a/bin

./startup.sh

(4) Open a new terminal and type the following command to launch the "Tc6_b" Tomcat instance

Cd/tc6_b/bin

./startup.sh

(5) Open the Third Terminal window and type the following command to start the Apache server.

/usr/local/apache2/bin/apachetl Start

(6) Enter "http://localhost/Hello.jsp" in the browser address bar and the page shown in Figure 4-2-2 will be entered.

Figure 4-2-2

(7) To refresh the page, the reader can see the page shown in Figure 4-2-3.

Figure 4-2-3

Description: Because Apache is a load balancer for the Tomcat cluster, it uses a rotation algorithm that evenly sends requests to each Tomcat instance in the cluster. Therefore, as can be seen from the above two images, it is a rotation to access the hello.jsp pages in two different Tomcat instances. Of course, seeing a rotation also indicates that the Apache load balancer is working properly.

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.