Forum Discussion
iRule for cookie based load balancing
- Jun 02, 2018
I am using below iRule and it works. I have single servers in pool and if the server is down LTM was throwing error.
when HTTP_REQUEST {
if { ([HTTP::cookie exists gcbSessionServer]) } {
if { ([HTTP::cookie value "gcbSessionServer"] contains ".Co-browse_TENCBSD0_Node1") and ([active_members cct-cobrowse-ct-node-1_pool] > 0)} {
pool cct-cobrowse-ct-node-1_pool
log local0. " COOKIE->[HTTP::cookie value "gcbSessionServer"] Selected pool [LB::select] " }
elseif { ([HTTP::cookie value "gcbSessionServer"] contains ".Co-browse_TENCBSD1_Node2") and ([active_members cct-cobrowse-ct-node-2_pool] > 0)} {
pool cct-cobrowse-ct-node-2_pool
log local0. " COOKIE->[HTTP::cookie value "gcbSessionServer"] Selected pool [LB::select] " }
elseif { ([HTTP::cookie value "gcbSessionServer"] contains ".Co-browse_TENCBSD2_Node3") and ([active_members cct-cobrowse-ct-node-3_pool] > 0)} {
pool cct-cobrowse-ct-node-3_pool
log local0. " COOKIE->[HTTP::cookie value "gcbSessionServer"] Selected pool [LB::select] " }
else {
LB::mode rr
pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool
log local0. " COOKIE FOUND Selected pool [LB::select] "
} }
else {
LB::mode rr
pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool
log local0. " NO COOKIE Selected pool [LB::select] "
} }
Better view of iRule:
when HTTP_REQUEST {
if { [HTTP::cookie exists gcbSessionServer] } {
switch [HTTP::cookie value "gcbSessionServer"] {
".Co-browse_TENCBSD0_Node1" {
pool cct-cobrowse-ct-node-1_pool
}
".Co-browse_TENCBSD0_Node2" {
pool cct-cobrowse-ct-node-2_pool
}
".Co-browse_TENCBSD0_Node3" {
pool cct-cobrowse-ct-node-3_pool
}
} }
else {
pool /Common/cct-cobrowse-ct.app/cct-cobrowse-ct_pool
log local0. " Selected pool [LB::select] "
}
}
Recent Discussions
Related Content
* 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