Apache 2.x+ jboss6.1 reverse proxy session Sharing Problem settings,
In August 4, 2016, I started my blog writing for the first time. Today, I solved a problem in my company.
Apache + jboss Server Load balancer has been plagued for a long time. The problem is described as follows. apche is used as a reverse proxy to forward to three jboss apps, which have session sessions. To avoid session loss during redirect, You need to configure the settings. After several days of searching, there are two methods:
1. Configure session sharing on jboss
2. apache forwards requests to accessed links
Session Processing
On the other hand, Session processing is performed between multiple business logic units. There are two Processing Methods: Session sticky mode and Session sharing mode.
Session Processing Method |
Session Sticky |
Session sharing |
Processing logic |
Send the Session of the same user to the same logical unit for processing. |
All backend processing logic units share sessions or notify other logic units when sessions are updated. |
Main Implementation Methods |
Specify the load distribution component (such as Apache), and send requests containing specific attributes to the same connection. For example, specify a request with the same jsessionid to the same request, or add a header attribute to each response in the load component to specify the next delivery destination. |
|
Advantages |
Local Session maintenance, no need to access network access or notify other processing unit changes |
Completely random distribution, you can adjust the distribution policy according to the service busy schedule, high availability |
Disadvantage |
When a server goes down, the current Session is disconnected. |
Network Access Operations and other time-consuming, affecting processing efficiency (depending on the selected policy) |
Official Document Description:
Examples of a balancer configuration
Before we dive into the technical details, here's an example of how you might usemod_proxy_balancer
To provide load balancing between two 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 usingmod_headers
, Even if the back-end server does not set a suitable 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, we can see that the Server Load balancer is actually 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 at will. Then, set the content of the balancer protocol in the <Proxy> section. The BalancerMember command can be used to add real server addresses in the Server Load balancer group.
Excerpt online information:
Configure Load Distribution
The following configuration changes are completed in the conf/httpd. conf configuration file of Apache.
1. Modify the module required to load mod proxy
Find the lines commented out in the configuration and delete the comments so that Apache can load the following modules at 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 it directly under the loadModule.
Header add Set-Cookie "ROUTEID =. % {BALANCER_WORKER_ROUTE} e; path =/" env = BALANCER_ROUTE_CHANGED
3. Configure the server Load balancer backend service logic unit processing address
Note that the marked red in this step must be consistent with the ROUTEID in the preceding 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 mod proxy routing rules
ProxyPass/balancer: // mycluster/
Note that do not add less "/". The name of mycluster is the same as that of the backend processing cluster above. This means that all requests are forwarded to the preceding cluster for processing.
The final configuration in Steps 5, 2, 3, and 4 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/