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.