prevent Src IP Persistence to sorry server
in aFleX
Posted by kberton
Attempting to create an aFlex that will set Src IP Persistence for all servers in a service group *except* for one server which is being used as a sorry server. I am setting priorities in the service group for each service and default behavior of AX is to apply the same persistence template to all member services. However, because the Priority 1 service is only a sorry server, I don't want persistence to apply to any sessions to this server so that when the higher priority services come back on-line, all users are load balanced to them instead of remaining sticky to the sorry server. Also, this is only at L4 so HTTP_REQUEST and _RESPONSE are not valid options for this particular requirement.
I have plagiarized and tweaked a sample aFlex shown below to no avail. Hoping someone in the Forum can set me straight. Thanks.
when CLIENT_ACCEPTED {
set sourcevalue [IP::client_addr]
set persistvalue [persist lookup uie $sourcevalue all]
if { $persistvalue ne "" } {
persist uie $cookievalue
log local0. "matched request"
}
}
when LB_SELECTED {
set servervalue [IP::server_addr]
if { ($persistvalue == "") and not ($servervalue == "172.29.253.11")} {
persist add uie $sourcevalue 600
log local0. "matched response"
}
}
Attempting to create an aFlex that will set Src IP Persistence for all servers in a service group *except* for one server which is being used as a sorry server. I am setting priorities in the service group for each service and default behavior of AX is to apply the same persistence template to all member services. However, because the Priority 1 service is only a sorry server, I don't want persistence to apply to any sessions to this server so that when the higher priority services come back on-line, all users are load balanced to them instead of remaining sticky to the sorry server. Also, this is only at L4 so HTTP_REQUEST and _RESPONSE are not valid options for this particular requirement.
I have plagiarized and tweaked a sample aFlex shown below to no avail. Hoping someone in the Forum can set me straight. Thanks.
when CLIENT_ACCEPTED {
set sourcevalue [IP::client_addr]
set persistvalue [persist lookup uie $sourcevalue all]
if { $persistvalue ne "" } {
persist uie $cookievalue
log local0. "matched request"
}
}
when LB_SELECTED {
set servervalue [IP::server_addr]
if { ($persistvalue == "") and not ($servervalue == "172.29.253.11")} {
persist add uie $sourcevalue 600
log local0. "matched response"
}
}
0
Comments
There were a couple of mistakes in your aFleX. For instance:
. You use a variable $cookievalue, but this one is not defined anywhere
. persist uie add can't be used in the even "LB_SELECTED" since you're not 100% sure the server selected is good and will reply
Here is the aFleX.
I tested it and it should work. Come back to us if you have questions.
BTW when you test, don't use "disable server" in the Service Group. When a server is disabled in the Service Group, it's still counted as active in "active_members". So to test it, the server has to be detected DOWN. (you can disable the server under "Server" though)
Note: I opened a bug against that "active_members" behavior.
Code:
when CLIENT_ACCEPTED { ####################### # Manual variables ####################### # Service Group pool name with all the production servers (no backup server in) # This is the service group configured in your VIP set pool_base your_pool_base_name # Service Group pool name with the backup server set pool_backup your_pool_backup_name ####################### # Set up variables automatically set client_ip [IP::client_addr] ####################### # Check if at least one production server is UP # And if so, check if the client is already in the persist uie table if {[active_members $pool_base] > 0} { # Check if the client has been active in the past 10 minutes set p [ persist lookup uie $client_ip all ] if { $p ne "" } { # That client has been found in the table # Check first the server is still UP before sending it to that one if {[LB::status pool $pool_base member [lindex $p 1] [lindex $p 2]] == "up"} { persist uie $client_ip log "Client $client_ip found in the table:[lindex $p 1]:[lindex $p 2]" } else { log "Client $client_ip found in the table: [lindex $p 1]:[lindex $p 2] but server DOWN" } } else { # That's a new client log "Client $client_ip not found in persistency-table" } } else { #The production servers are dead, use the pool_backup log "All production servers are dead, use backup pool: $pool_backup" pool $pool_backup } } when SERVER_CONNECTED { # If the production servers have been used # Update persist uie table with Client IP@ information and aging time if {[active_members $pool_base] > 0} { persist add uie $client_ip 600 log "Add/Update persist entry for client $client_ip with server [LB::server addr]" } }
I just realized I used some aFleX commands enhanced in 2.6.1:
. The test to be sure the server is still UP):
if {[LB::status pool $pool_base member [lindex $p 1] [lindex $p 2]] == "up"} {
. And the log :
log "Add/Update persist entry for client $client_ip with server [LB::server addr]
But since 2.6.1 is almost out of the door, I guess that's all good