Forum Discussion

arun_parthas_10's avatar
arun_parthas_10
Icon for Nimbostratus rankNimbostratus
Mar 18, 2009

Need help with writing an Irule

Hi

 

 

I have a situation where I have 4 clients hitting a VIP with two servers behind..

 

I am having a Least Connection ( member ) as LB method and Persistence set for 4 hours.. the problem I am having is that 3 clients are bound to server1 and 1 remaining client connect to server 2.. I need help in writing a iRule where I would like to force clients 1&2 to Server 1 ( have Server 2 as failback host ) and client 3 and 4 to Server 2 ( have Server 1 as failback host ), so I make use of both servers on the backend equally.. I will not need to use persistence if I can achieve this . Please see the scenario mentioend below :

 

 

1. Tie the first two external hosts ( apache1, apache2 ) with one backend host1 (new pool ) also by having a backup host2.

 

2. Tie the Second two external hosts ( apache3, apache4 ) with one backend host2 (new pool ) also by having a backup host1.

 

 

Any help on this would be greatly appreciated.

 

 

Arun P

8 Replies

  • Hi Arun,

    I would say the easiest solution is to just use Round Robin with persistence. That should result in more even distribution.

    You could also do this without an iRule if you just create 2 pools, one with server 1 having more priority, and the other with server 2 having priority. Then use 2 vips pointing to those respective pools, one for clients 1 and 2, the other for clients 3 and 4.

    Or you could use a rule to select between those 2 pools based on client IP address, but it seems that you're artificially limiting yourself if you do it that way.

    Something like:

     
     when CLIENT_ACCEPTED { 
       if { ([IP::addr [IP::client_addr] equals x.x.x.x) || ([IP::addr [IP::client_addr] equals y.y.y.y) 
          pool pool1  
         } else { 
          pool pool2 
     } 
     } 
     

    (Not syntax checked...)

    Denny
  • Hi Denny

     

     

    Thanks for your response.. We did have LB with Round Robin with Persistence and the results were horrible.. all four client IP going to one server.. changing it to LC ( member) and rebooting the Bigip atleast got us 3 to 1.

     

     

     

     

    The syntax you have given forces first two client IP's to a Pool with one server.. Not sure what happens if server in Pool 1 goes off line :

     

     

    when CLIENT_ACCEPTED { if { ([IP::addr [IP::client_addr] equals x.x.x.x) || ([IP::addr [IP::client_addr] equals y.y.y.y) pool pool1 } else { pool pool2 } }

     

     

    As mentioned, I would probably like to try out with IRulewhere tie clients 1 & 2 to a Pool with Server1 and 3 & 4 to a Server2 by having other pools as fall back..

     

     

     

    Would you be able to help with syntax ?

     

     

    thanks in advance.

     

     

    Arun P
  • The syntax you have given forces first two client IP's to a Pool with one server.. Not sure what happens if server in Pool 1 goes off line

     

     

     

     

    No the pools would both have 2 servers, but you use priority groups in the pool settings to give one server in each pool higher priority over the other. Then if the primary server fails the backup is used.

     

     

    Denny
  • Denny

     

     

    I wrote this iRule below and getting an error :

     

     

     

     

    when CLIENT_ACCEPTED {

     

    if { ([IP::addr [IP::client_addr] equals 172.24.81.20) || ([IP::addr [IP::client_addr] equals 172.24.8.16)

     

    pool beta-cpc-web-pool-1-12100

     

    } else {

     

    pool beta-cpc-web-pool-2-12100

     

    }

     

    }

     

     

    error :

     

     

     

    01070151:3: Rule [CPC-LB-TEST] error: line 2: [parse error: PARSE missingBracket 86 {missing close-bracket}] [{ [IP::addr [IP::client_addr] equals 172.24.81.20 || [IP::addr [IP::client_addr] equals 172.24.8.16 pool beta-cpc-web-pool-1-12100 }] line 4: [undefined procedure: else] [else] line 4: [deprecated usage, use else or elseif] [ ]

     

     

    Can you pleae help ?
  • The error mentions you're missing close brackets - it looks like they're missing off of the IP::addr command. Try this (haven't tested it)

     
     when CLIENT_ACCEPTED { 
     if { ([IP::addr [IP::client_addr] equals 172.24.81.20]) || ([IP::addr [IP::client_addr] equals 172.24.8.16]) 
     pool beta-cpc-web-pool-1-12100 
     } else { 
     pool beta-cpc-web-pool-2-12100 
     } 
     }  
     

    -Matt
  • Matt

     

     

    Thanks for the response.. it doesnt work however :

     

     

    01070151:3: Rule [TEST-CPC-IRULE] error: line 2: [parse error: PARSE syntax 132 {syntax error in expression [IP::addr [IP::client_addr] equals 172.24.81.20] || [IP:...: extra tokens at end of expression}] [{ [IP::addr [IP::client_addr] equals 172.24.81.20] || [IP::addr [IP::client_addr] equals 172.24.8.16] pool beta-cpc-web-pool-1-12100 }] line 4: [undefined procedure: else] [else] line 4: [deprecated usage, use else or elseif] [ ]

     

     

     

    when CLIENT_ACCEPTED {

     

    if { ([IP::addr [IP::client_addr] equals 172.24.81.20]) || ([IP::addr [IP::client_addr] equals 172.24.8.16])

     

    pool beta-cpc-web-pool-1-12100

     

    } else {

     

    pool beta-cpc-web-pool-2-12100

     

    }

     

    }
  • what about this:

     
     when CLIENT_ACCEPTED { 
     if { ([IP::addr [IP::client_addr] equals 172.24.81.20]) || ([IP::addr [IP::client_addr] equals 172.24.8.16]) } { 
     pool beta-cpc-web-pool-1-12100 
     } else { 
     pool beta-cpc-web-pool-2-12100 
     } 
     }