August 4, 2016, the first time writing wrote a blog park, today in the company to solve a problem.
The problem of Apache+jboss doing load balancing has been troubling for a long time. The problem is described below, using Apche to do reverse proxy forwarding to 3 JBoss App,app with session sessions. In order to jump without losing session sessions, you need to configure. After a few days of searching, there are probably two ways:
1. Configure session sharing on JBoss
2. Apache requests forward to the visited link
Session processing
On the other hand is the session between multiple business logic units processing, there are two ways, one is the session sticky mode, the other is the session sharing mode.
Session processing Mode |
Session Sticky |
Session sharing |
Processing logic |
The same user's session is sent to the same logical unit for processing |
All back-end processing logic units share session or session updates to notify other logical units |
Main implementation Methods |
Specify the distribution component of the payload (such as Apache), send requests that contain specific attributes to the same connection, such as specifying jsessionid consistent requests to the same request, or adding a header attribute to each response in the load component, specifying the next distribution destination |
- Each maintenance session, when the request processing is finished, notifies other component units to update the session, including asynchronous and synchronous modes
- Unified Maintenance session, such as the session in the Memcached or shared file system, can be at the container level or application level to do this thing
- Using the cache server
|
Advantage |
Local maintenance session, no need to access network access or notify other processing unit changes |
Full random distribution, can adjust distribution policy based on service busy, high availability |
Disadvantage |
The current session is disconnected after a server is down |
Network access operations, such as time-consuming, impact processing efficiency (depending on the choice of strategy different impact) |
Official Document Description:
Examples of a balancer configuration
Before we dive into the technical details, here's a example of how do you might use to mod_proxy_balancer
provide load balancing between Back-end servers:
<Proxy balancer://mycluster>
BalancerMember http://192.168.1.50:80
BalancerMember http://192.168.1.51:80
</Proxy>
ProxyPass /test balancer://mycluster
Another example of how to provide load balancing with stickyness using mod_headers
, even if the Back-end server does not set a s Uitable Session Cookie:
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Proxy balancer://mycluster>
BalancerMember http://192.168.1.50:80 route=1
BalancerMember http://192.168.1.51:80 route=2
ProxySet stickysession=ROUTEID
</Proxy>
ProxyPass /test balancer://mycluster
Proxyrequests Off This can be seen, in fact, the load balancer is a reverse proxy, but its proxy forwarding address is not a specific server, but a balancer://protocol: proxypass/balancer:// The Mycluster protocol address can be defined casually. Then, set the contents of the Balancer protocol in the <Proxy> section. The balancermember instruction can add a real server address in a Load balancer group.
Excerpt online Information:
Configure load Distribution
The following configuration modifications are done in the Apache conf/httpd.conf configuration file
1. Modify the module required to load the MoD proxy
Find the lines that are commented out in the configuration and delete the comments so that Apache loads the following modules on startup
LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule Proxy_connect_module modules/mod_proxy_connect.so
LoadModule Proxy_http_module modules/mod_proxy_http.so
LoadModule Headers_module modules/mod_headers.so
LoadModule Status_module modules/mod_status.so
2. Add a route ID to the HTTP request header
Add directly below the LoadModule module
Header add Set-cookie "routeid=.%{balancer_worker_route}e; path=/"env=balancer_route_changed
3. Configure the Business logic unit processing address for the load balancer backend
Note the need for this step to be red is consistent with the Routeid in the previous step.
<proxy balancer://mycluster>
Balancermember http://192.168.77.213:9005 route=1
Balancermember http://192.168.77.213:9004 route=2
Balancermember http://192.168.77.213:9002 route=3
Balancermember http://192.168.77.213:9003 route=4
Proxyset Stickysession=routeid
</Proxy>
4. Configure the MoD proxy routing rule
proxypass/balancer://mycluster/
Note "/" Do not add less, mycluster is consistent with the name of the back-end processing cluster above. This means that all requests are forwarded to the cluster above for processing.
5. The final configuration of the 2,3,4 step is as follows:
Header add Set-cookie "routeid=.%{balancer_worker_route}e; path=/"env=balancer_route_changed
<proxy balancer://mycluster>
Balancermember http://192.168.77.213:9005 route=1
Balancermember http://192.168.77.213:9004 route=2
Balancermember http://192.168.77.213:9002 route=3
Balancermember http://192.168.77.213:9003 route=4
Proxyset Stickysession=routeid
</Proxy>
proxypass/balancer://mycluster/
Apache 2.x+jboss6.1 Reverse Proxy session sharing problem settings