For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

sandiksk_35282's avatar
sandiksk_35282
Icon for Altostratus rankAltostratus
Sep 24, 2015

need help with an irule

I have 2 app serves i.e need to talk to the database VIP,load balancing 2 database servers. How can I create an irule so that

 

app server 1 --- always talk to database server 1 app server 2------always talk to database server2.

 

9 Replies

  • At the first look, you will not need an iRule for that. If I understand your scenario, you want to remove the load-balancing and high-availability for the DB service. As you described your scenario:

     

    - App Server 1 communicates to DB1 (always)

     

    - App Server 2 comminicates to DB2 (always)

     

    Can you specify what should happen if one of the DB servers fails? i.e DB1 comes unavailable, should the traffic from App Server 1 land in the DB2 server or is it not important?

     

  • yes that is how it should work

     

    App server1 --- DB1 App server2----DB2

     

    If either DB server fails then Ap1 and Ap2 should communicate to the other available database server.

     

  • Given the requirement to cover for High Availability despite strict IP-based routings, you're better off using an iRule.

     

    I believe the code below covers your requirements.

     

    Please give it a try and let me know if you have any questions. Replace the values of IP addresses, port numbers and the don't forget to modify the pool name "DB_servers_pool".

     

    when CLIENT_ACCEPTED {
    
    
      if { [active_members DB_servers_pool] < 2}{
         Bypass the execution of strict IP-based routing. Allows F5 to select any node that is available
        return
      } elseif { [IP::client_addr] == "1.1.1.1" }{
         Explicitly forward App Server 1 traffic to a specific database pool member via TCP port 3306
        pool DB_servers_pool member 10.10.10.1 3306
      } elseif { [IP::client_addr] == "1.1.1.2" }{
         Explicitly forward App Server 2 traffic to a specific database pool member via TCP port 3306
        pool DB_servers_pool member 10.10.10.2 3306
      }
    
    }

    Regards,

     

  • doi need specify the port or can I get have the irule as below

     

    when CLIENT_ACCEPTED {

     

    if { [active_members DB_servers_pool] < 2}{ return } elseif { [IP::client_addr] == "1.1.1.1" }{ pool DB_servers_pool member 10.10.10.1 } elseif { [IP::client_addr] == "1.1.1.2" }{ pool DB_servers_pool member 10.10.10.2 }

     

    }

     

    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus
      Yes, specifying the port is optional. By not specifying, the port number will be the same as configured in your database servers pool. If the database servers pool does not have a port specified (port 0), then the port number will be the same as target port of the established clientside connection.
  • and i more question if anyother source makes a connection to the database servers it should be based on the predictor and persistence correct .Only App1 and app2 traffic will be directed to the database servers based on the irule.

     

    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus
      That's correct. However, given the new details I recommend you take into use "persist none" function - add it to both of the ELSEIF blocks so no persistency records will be created for those two app servers. I've also updated my original iRule code.
  • when CLIENT_ACCEPTED {
    
      if { [active_members DB_servers_pool] < 2 }{
        return
      } elseif { [IP::client_addr] == "1.1.1.1" }{
        persist none
        pool DB_servers_pool member 10.10.10.1
      } elseif { [IP::client_addr] == "1.1.1.2" }{
        persist none
        pool DB_servers_pool member 10.10.10.2
      }
    
    }
    
  • Thanks a lot for your help ,finally I got this irule tested and its working . want to know if we need to enabled presistence rebalance where do i get this setup on http profile.