Forum Discussion
Gary_Bright_120
Nimbostratus
Mar 13, 2006Persist iRule based on URI
Hi there I'm trying to write an iRule that will allow us Admins the choice of selecting a pool member and have persistence with that member.
At the moment we have a persistance profile or source_addr on the virtual server which holds for 15 minutes. This works great.
The pool is made up for 4 members
here is my first attempt
when HTTP_REQUEST {
if { [URI::decode [string tolower [HTTP::uri]]] contains "lbmember=3" } {
persist none
pool pool_name member 1.1.1.1 80
persist source_addr 1800
}
}
Would someone be able to help me out with how I should go about setting this up.
To test I connect from my machine to the pool then view the persisent records in statistics find out which member I'm going to (not member 3) , then I refresh my page with lbmember=3 in the URL, but my persistence record still points to the old server and not 3
TIA
Gary
- JRahm
Admin
I think you probably want an else statement in there for the src_addr persist statement, otherwise, the persist none is reset to src_addr before the condition is completed. - James_Thomson
Employee
Wouldn't you want it the other way around? If you find gb=3, persist none because there's only one server to send you to so you don't need to persist.when HTTP_REQUEST { if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=" } { persist source_addr 1800 log "Persist" } if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=3" } { use pool webpool member 1.1.1.3 80 persist none log "NO -- Persist" } } I think persistence takes precedence over selecting a pool member directly. Can anyone confirm that?
- Gary_Bright_120
Nimbostratus
There are three member in the poolwhen HTTP_REQUEST { if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=" } { persist none log "Persist Turn Off" } if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=3" } { use pool webpool member 1.1.1.3 80 persist source_addr 1800 log "Persist Setup to Member 3" } if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=2" } { use pool webpool member 1.1.1.2 80 persist source_addr 1800 log "Persist Setup to Member 2" } if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=1" } { use pool webpool member 1.1.1.1 80 persist source_addr 1800 log "Persist Setup to Member 1" } }
- Deb_Allen_18Historic F5 AccountSince you are trying to insert a persistence record, rather than use an existing one, I think you need to use "persist add", and place the command AFTER the load balancing decision, so it can add the results of the load balancing decision to the persistence table:
if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=3" } { pool webpool member 1.1.1.3 80 persist add source_addr 1800 log "Persist Setup to Member 3" }
- Gary_Bright_120
Nimbostratus
Thanks for all your replyswhen HTTP_REQUEST { if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=" } { persist none log "Persist Turn Off" } if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=4" } { pool member_www_04 member 4.4.4.4 80 pool member_www_04 persist source_addr 1800 log "Persist Setup to Member 4" } if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=3" } { pool member_www_03 member 3.3.3.3 80 pool member_www_03 persist source_addr 1800 log "Persist Setup to Member 3" } if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=2" } { pool member_www_02 member 2.2.2.2 80 pool member_www_02 persist source_addr 1800 log "Persist Setup to Member 2" } if { [URI::decode [string tolower [HTTP::uri]]] contains "gb=1" } { pool member_www_01 member 1.1.1.1 80 pool member_www_01 persist source_addr 1800 log "Persist Setup to Member 1" } }
- unRuleY_95363Historic F5 AccountOh, yep. That is a bug. Using direct pool member selection doesn't cause a persistence record to be created (or a persist cookie to be inserted). You can add the persist record in an LB_SELECTED event like so (I've also made a few other optimizations):
when HTTP_REQUEST { switch -glob [URI::decode [string tolower [HTTP::uri]]] { *gb=1* { pool webpool member 1.1.1.1 80 set need_add_persist 1 } *gb=2* { pool webpool member 2.2.2.2 80 set need_add_persist 1 } *gb=3* { pool webpool member 3.3.3.3 80 set need_add_persist 1 } *gb=4* { pool webpool member 4.4.4.4 80 set need_add_persist 1 } *gb=* { persist none log "Persist Turn Off" } } } when LB_SELECTED { if {[info exists need_add_persist]} { persist add source_addr [IP::client_addr] 1800 unset need_add_persist } }
- Gary_Bright_120
Nimbostratus
Thank You very much for your help
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects