Forum Discussion
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
- Hannes_Rapp
Nimbostratus
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?
- sandiksk_35282
Altostratus
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.
- Hannes_Rapp
Nimbostratus
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,
- sandiksk_35282
Altostratus
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
Nimbostratus
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.
- sandiksk_35282
Altostratus
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
Nimbostratus
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.
- Hannes_Rapp
Nimbostratus
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 } } - sandiksk_35282
Altostratus
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.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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