Apache + Tomcat configure reverse proxy, server load balancer, and cluster (mod_proxy mode)

Source: Internet
Author: User
There are many ways for Apache to configure server load balancer and clusters to use mod_jk. However, mod_jk has stopped updating and the configuration is relatively complex. After Apache2.2, server load balancer and clusters are configured in a native way, which is much simpler than mod_jk. 1. Apache configuration reverse proxy forward proxy generally refers to a PC connected to the proxy server, where the proxy server forwards requests to the website. Reverse proxy

There are many ways for Apache to configure server load balancer and clusters to use mod_jk.
However, mod_jk has stopped updating and the configuration is relatively complex.
After Apache2.2, server load balancer and clusters are configured in a native way, which is much simpler than mod_jk.

1. configure reverse proxy for Apache
A forward proxy is usually used to connect a PC to the proxy server, and the proxy server forwards requests to the website. Reverse proxy refers to sending requests to the reverse proxy server, where the reverse proxy server forwards the requests to the specific server.
For example, the data center has two Tomcat services, but users cannot directly access them due to firewall reasons. At this time, you can use the reverse proxy server to forward requests to Tomcat. The firewall only needs to enable the port of the reverse proxy server.

The following experiment assumes that the intranet Tomcat provides the Google service, and the internet accesses this service through reverse proxy.
Modify/etc/httpd/conf/httpd. conf to add the following configuration:

Access Link: http: // 192.168.1.105/google

2. server load balancer
Server load balancer should be the most common horizontal scaling technology. Apache server load balancer forwards frontend requests to the backend Tomcat server according to the configured proportion, which improves the concurrent access volume. As a mod_proxy method, it is very easy to configure server load balancer, that is, sending requests to the server load balancer based on the reverse proxy.
First, modify the web. xml file of the War package program and add ID.
Second, modify the server. xml of each Tomcat server and configure jvmRoute ????

Finally, modify the httpd. conf file of apache and add the following content:

ProxyPass/images! Requests starting with/images are not forwarded to Tomcat, but are used as static resources to search for resource files in the images directory of Apache.
The reverse proxy forwards all/Test requests to the balancer named mycluster.
This balancer has two Tomcat members.

Loadfactor indicates the request weight. the default value is 1. you can set this value to any value between 1 and 100. Lbmethod indicates the server load balancer algorithm. lbmethod may take the following values: lbmethod = byrequests (default) lbmethod = bytraffic balanced by traffic lbmethod = bybusyness balanced by the degree of busy (always allocated to the server with the least number of active requests)

StickySession = JSESSIONID indicates that stickySession is enabled. It means that if the first request is sent to Tomcat of worker1, subsequent requests of this user will be allocated to the Tomcat of worker1.
View sticky sessions on a test page

Index. jsp

As you can see, due to the role of sticky sessions, the repeated operations on the web page are all sent to the same Tomcat (worker2) by Apache)

View the cookie information of firefox. apache implements a sticky Session based on the routeid following JSESSIONID.

3. Cluster
I think the difference between clusters and server load balancer is that clusters include Session replication and failover.
Session replication is in a broad sense. In fact, when a failover occurs, you can continue to read the user's Session.
Session replication is only one of the methods. you can also use the Session server method.
For example:

Http://blog.itpub.net/29254281/viewspace-1063018/

Configure clusters based on server load balancer
First, enable Tomcat Session replication.

Configure failover in Apache (nofailover = Off)

After the cluster is configured, the request comes from the front end. if it is assigned to worker1, it will always access worker1.
If worker1 goes down, subsequent requests of this user will be automatically transferred to worker2.
Session information is not lost because Tomcat is configured with Session replication.
The entire process is completely transparent to users.

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.