Configure reverse proxy, Server Load balancer, and clusters in Apache (mod_proxy Mode)

Source: Internet
Author: User

Configure reverse proxy, Server Load balancer, and clusters in Apache (mod_proxy Mode)

There are many ways for Apache to configure Server Load balancer and clusters to use mod_jk, but 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

Apache reverse proxy settings

Apache acts as a reverse proxy server

Apache-multi-site log analysis

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, Server Load balancer configuration is very simple, that is, requests are sent to balancer Based on the reverse proxy.
First, modify the web. xml file of the War package program and add the <distributable/> identifier.
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:

Implementation of Apache Load Balancing

CentOS 6.4 LVS Server Load balancer VS/NAT mechanism (one master and one slave provide redundancy)

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 load balancing algorithm. lbmethod may take the following values:
Lbmethod = byrequests balanced by the number of requests (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

<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
 
PageEncoding = "UTF-8" %>

<% @ Page import = "java. util. *" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">

<Html>

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">

<Title> Insert title here </title>

</Head>

<Body>

<%

System. out. println (session. getId ());

Out. println ("<br> session id:" + session. getId () + "<br> ");

// If a new request exists, the session attribute is added.

String name = request. getParameter ("name ");

If (name! = Null & name. length ()> 0 ){

String value = request. getParameter ("value ");

Session. setAttribute (name, value );

}

Out. print ("<B> Session List: </B> ");

Enumeration <String> names = session. getAttributeNames ();

While (names. hasMoreElements ()){

String sname = names. nextElement ();

String value = session. getAttribute (sname). toString ();

Out. println (sname + "=" + value + "<br> ");

System. out. println (sname + "=" + value );

}

%>

<Form action = "index. jsp" method = "post">

Name: <input type = text size = 20 name = "name">

<Br>

Value: <input type = text size = 20 name = "value">

<Br>

<Input type = submit value = "submit">

</Form> </body>

</Html>
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.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.