Forum Discussion
11.4 node/pool select according to domains list
Hello, I need to perform node/pool selection according to big domains list. I have a list of 500 domains that have to be routed to a specific node, all other domains should be routed to the second node. Both nodes in the same pool. I can also create 2 different pools and do the same.
I am running 11.4, how should I do that? Please provide me with example of irule. Please note that in 11.4 there are Policies instead of http class.
Thanks.
24 Replies
- Kevin_Stewart
Employee
Thanks, can I make it easier so if there is a match from the list then go to pool1 otherwise go to pool2, then I will just put the first half in the list without specifying a pool.
Certainly. Create the data group with the first set of domains, then modify the iRule accordingly:
when HTTP_REQUEST { if { [class match [string tolower [HTTP::host]] equals my_domain_dg] } { pool pool1 } else { pool pool2 } }In this version, your data group entries don't have to have a corresponding pool or node value - just enter the domain name as the key and leave the value blank (we're not going to use it). Then create TWO pools: pool1 for domains that are in the data group, and pool2 for everything else.
- BinaryCanary_19Historic F5 Account
Yes you can. The first match goes to pool1, the second match (without a condition) goes to pool 2. pseudocode is below (adapt to correct irule syntax):
if (match) { go to pool 1 }else { go to pool 2 }Note that the value of the string is irrelevant, depending on how you structure the class match in your irule. For instance, the values of the strings are irrelevant if you use "class exists" in stead of "class match". Class exists simply checks if the element exists in the class, so if your data group is a list of "domain" := "an IP address", then class exists is convenient as it ignores the IP address set in the datagroup, and simply checks if this domain is in the list:
if {class exists HTTP::host} { pool pool1 }else { pool pool2 }You need a datagroup of type String. And the datagroup example Kevin gave should work for this. You have to as usual, be careful of the hostnames you specify, especially if your site is both accessible as "www.domain.com" and just "domain.com". You either need to set things up so that clients always get redirected to one kind, or you include both kinds of hostnames in the datagroup.
Reference: class command: https://devcentral.f5.com/wiki/irules.class.ashx
- Dmitry_Sherman
Nimbostratus
I made this irule:
when HTTP_REQUEST { if { [class match [string tolower [HTTP::host]] contains iwin2_list] } { pool iwin2_pool } else { pool iwin_http_pool } }the datagroup iwin2_list contains a host without 'www', is it the correct way to do this?
- Kevin_Stewart
Employee
It should work. But to elaborate on what aFanen01 is saying, you have to be careful with the string matches. If, for example, you have two domains: www1.example.com and www2.example.com in the data group, then doing contains ".example.com" or ends_with ".example.com" will match two records - perhaps undesirably.
- Dmitry_Sherman
Nimbostratus
Thanks for help guys, it worked!
- Dmitry_Sherman
Nimbostratus
Customer can add more domains in future, since its dynamic hosting environment, Is it possible to load external datagroup list file which can be updated periodically?
Or is there any API in F5 that can be used as upload url where I can upload the update datagroup ?
- Dmitry_Sherman
Nimbostratus
Does the dg file should look like that: "www.domain1.com" := "www.domain1.com" "www.domain2.com" := "www.domain2.com" "www.domain3.com" := "www.domain3.com"
- Kevin_Stewart
Employee
Customer can add more domains in future, since its dynamic hosting environment, Is it possible to load external datagroup list file which can be updated periodically? Or is there any API in F5 that can be used as upload url where I can upload the update datagroup ?
There are several ways to manage data groups. You can use an internal data group (that gets stored in the config), or an external, file-based, data group. In both cases you can use iControls remotely and shell scripts (bash, perl, python, etc.) locally to manage the content of the data groups. It really depends on how you want to do it.
Does the dg file should look like that: "www.domain1.com" := "www.domain1.com" "www.domain2.com" := "www.domain2.com" "www.domain3.com" := "www.domain3.com"
You don't need a value in the data group - just the string. Example:
www.domain1.com := www.domain2.com := www.domain3.com := www.domain4.com := ... - Dmitry_Sherman
Nimbostratus
Thanks a lot all worked!
- Kevin_Stewart
Employee
I get an error when i try to import
Please see Jason Rahm's description of external data groups. You probably have some hidden "Windows" characters in your text causing the problem:
v11: iRules Data Group Updates
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