Apache Server Load balancer Configuration

Source: Internet
Author: User

Source: http://steven2011.iteye.com/blog/1296588

Download: http://httpd.apache.org/(test with version 2.2)
Document: http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html

Apache2.2 \ conf \ httpd. conf

1. enable the required module (find the corresponding module and uncomment it)

Loadmodule proxy_module modules/mod_proxy.so
Loadmodule proxy_balancer_module modules/mod_proxy_balancer.so
Loadmodule proxy_http_module modules/mod_proxy_http.so

# This is used to create a cookie for session sticky. If you use an existing Web Server cookie such as JSESSIONID, you do not need to enable it.
Loadmodule headers_module modules/mod_headers.so

2. Configure the load parameters

/Test: proxy path
Lbmethod: Currently, there are three options: byrequests, bytraffic, and bybusyness.
Route: The identifier of the Server Load balancer Member, used for session sticky.
Header: when the temporary variable balancer_route_changed is set to establish a connection for the first time or when the server load balancer_route_changed fails to switch the server load, the cookie name is routeid and the value is. add the configured route value, such as set-Cookie routeid =. node1
Stickysession: indicates the cookie name of the session.

Header add set-cookie "routeid =. % {balancer_worker_route} e; Path =/" Env = balancer_route_changed
<Proxy balancer: // cluster_test>
Balancermember http: // 192.168.1.6: 8000/test loadfactor = 3 route = node1
Balancermember http: // 192.168.1.6: 9000/test loadfactor = 1 route = node2
</Proxy>
Proxypass/test balancer: // cluster_test lbmethod = byrequests stickysession = routeid

You can configure the following attributes:
Nofailover is off by default, indicating that the Failover function is enabled. If you disable (on), the error 503 service temp unavaliable will be returned if the selected load member is down.

Failonstatus can be used to specify the load member's response HTTP status code, which can be considered as a load member's downtime, such as 404,500. By default, only the connection error is considered as a load member's downtime.

NOTE: If Apache determines that the Server Load balancer member is down, the Server Load balancer member that has been down will be used again in 1 minute by default.
In addition, in the case of failonstatus, only the next request will fail, and the first request will send the corresponding error message, such as 500 or 404, to the client.

In addition, we can also use the session cookie, such as JSESSIONID, that comes with the server load Member Server. The following is the configuration for Tomcat.
Apache2.2 \ conf \ httpd. conf

<Proxy balancer: // cluster_test>
Balancermember http: // 192.168.1.6: 8000/test loadfactor = 3 route = node1
Balancermember http: // 192.168.1.6: 9000/test loadfactor = 1 route = node2
</Proxy>
Proxypass/test balancer: // cluster_test lbmethod = byrequests stickysession = JSESSIONID

Apache-Tomcat-6.0.18 \ conf \ Server. xml
<Engine name = "Catalina" defaulthost = "localhost" jvmroute = "node1">

In this way, the value of JSESSIONID is followed by. node1 or. node2.
JSESSIONID = 3e5f7cc704192e0bfbaf1190a1ef513a. node1

Note that JSESSIONID is case sensitive.

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.