Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Detailed explanation of how to realize apache+tomcat load balancing configuration

Shulou Source: shulou.com Published: 2022-06-03 07:52:24 11月23日 Update

The following gives you a detailed explanation of how to achieve apache+tomcat load balancing configuration, hoping to give you some help in practical application. Load balancing involves a lot of things, there are not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

1. System environment

Win7-64, jdk

two。 Software list:

Apache_2.2.24-x64-no-ssl.msi 、 tomcat5

3. Instructions for configuration steps:

1) configure which method is used to achieve load balancing.

2) change the port related to the tomcat profile (I tested it on this machine, which has multiple tomcat)

3) docking apache and tomcat

4. Configuration start

1) modify the conf/httpd.conf file under the apache installation directory

Remove the following comments (that is, go to the #), what is the use? After cancellation, you can use proxy (proxy) to achieve load balancing! (lines 111-116)

1 LoadModule proxy_module modules/mod_proxy.so2 LoadModule proxy_ajp_module modules/mod_proxy_ajp.so3 LoadModule proxy_balancer_module modules/mod_proxy_balancer.so4 LoadModule proxy_connect_module modules/mod_proxy_connect.so5 LoadModule proxy_ftp_module modules/mod_proxy_ftp.so6 LoadModule proxy_http_module modules/mod_proxy_http.so

And the code that loads a configuration file should also be released (line 471)

1 Include conf/extra/httpd-vhosts.conf

2) configure tomcat

Modify the various ports in your Tomcat\ conf\ server.xml file (too simplistic and skip)

3) configure VirtualHost

Add it to the conf/extra/httpd-vhosts.conf file of the apache installation directory, and you don't need to add it. The port can also be changed here, including ip, which is *

ServerAdmin administrator mailbox ServerName localhost ServerAlias localhost ProxyPass / balancer://sy/ stickysession=jsessionid nofailover=On ProxyPa***everse / balancer://sy/ ErrorLog "logs/sy-error.log" CustomLog "logs/sy-access.log" common

4) docking

The point is, docking, yes, is the following code, written in the conf/httpd.conf under the apache installation directory (this file can also modify the port settings).

What is emphasized here is the port number, which is explained by the default port of tomcat, such as port 8080, port 8009, and you use 8080 to access tomcat directly.

But in this case, it's 8009.

ProxyRequests Off BalancerMember ajp://127.0.0.1:18009 loadfactor=1 route=jvm1 BalancerMember ajp://127.0.0.1:28009 loadfactor=1 route=jvm2

5. test

1) create a new project and deploy to tomcat

2) start apache,tomcat and visit

3) if you encounter a visit page that displays Service Temporarily Unavailable

Then please read step 4 carefully.

6.sessino sharing, release the server.xml under tomcat,conf

Tags: Configuration port file balance code project that is technology framework directory cache in line Baba security no industry distributed workflow engineering engineer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi Shulou Information MySQL vpn