Contributed by: unRuleY
Summarized by: deb
Description
Provides persistence on the JSessionID value found in either the URI or a cookie.
To persist on JSessionID, create the iRule below and apply via a primary Persistence profile of type "universal" with a session-appropriate idle timeout. If URI-based JSessionID values are used, also apply a Fallback Persistence profile profile of type Source Address with a host mask and a short timeout. (The default source_addr persistence profile will do the trick.)
When a request is received, the iRule first looks for a "JSessionID" cookie, and if not found, for a "JSessionID" parameter in the requested URI. If either is found, a persistence record is created if it doesn't already exist, or followed if it does. If neither is found, the request is load balanced according to the load balancing method applied to the virtual server.
In order to ensure the second and subsequent requests follow the first, LTM must create a persistence record indicating the pool member to which the first request was load balanced. If the server is setting the JSessionID in a cookie, the persistence key value may be extracted from the server response to create the persistence record. If the server is setting the JSessionID in the URLs, source address persistence with a short timeout is recommended to track the original destination until the JSessionID is sent. 为啥URLs里的就不能取?
Implementation Notes:
This iRule is intended to be applied under a Universal persistence profile configured with an appropriate timeout. If it is instead applied directly to a virtual server as a Resource, it must be modified to add a persistence timeout parameter to the "perist add" command.
To ensure a new persistence record is followed when a request is re-load balanced in a client-side Keep-Alive connection, apply a OneConnect profile to the virtual server. (If OneConnect is not desired, the pool should have "Action on Service Down" set to "Reject", forcing a new connection on server failure.)
不启用oneconnect的时候 , 如果客户端利用keep-alive在相同的连接上发起了新请求,那么此时会话保持只能根据最先的那个连接保持信息进行,这样的话会导致应该进行新会话保持(这个连接应该被负载均衡)的连接还使用了以前的保持信息,不能充分进行负载均衡。所以对会话保持最好是启用oneconnect profile。
iRule Source
1 2 3 4 |
rule WeblogicJSessionPersist { <br /> when HTTP_REQUEST { <br /> if { [HTTP::cookie exists "JSessionID"] } { <br /> persist uie [HTTP::cookie "JSessionID"] <br /> } else { <br /> set jsess [findstr [HTTP::uri] "JSessionID" 11 ";"] <br /> if { $jsess != "" } { <br /> persist uie $jsess <br /> } <br /> } <br /> } <br /> &nbs p; when HTTP_RESPONS E { <br /> if { [HTTP::cookie exists "JSessionID"] } { <br /> persist add uie [HTTP::cookie "JSessionID"] <br /> } <br /> } <br /> } <br /> |
文章评论