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
As an iRule, this sounds like an excellent candidate for a data group.
Step 1: create a string-based data group consisting of domain names and corresponding nodes. Example (my_domain_dg):
"www.domain1.com" := "10.10.10.11 80" "www.domain2.com" := "10.10.10.12 80" "www.domain3.com" := "10.10.10.13 80" "www.domain4.com" := "10.10.10.14 80" ... "www.domain500.com" := "10.10.10.510 80"And a reasonably simple iRule:
when HTTP_REQUEST { if { [class match [string tolower [HTTP::host]] equals my_domain_dg] } { set my_node [split [class match -value [string tolower [HTTP::host]] equals my_domain_dg]] node [lindex $my_node 0] [lindex $my_node 1] } }You can also use this method with pools, which may be a better option in the future if you're going to need to actually load balance and scale out services. The beauty of this approach is that you manage a single data group and don't really have to touch the iRule.
...And you can also do this with policies in 11.4
- Dmitry_Sherman
Nimbostratus
Hello thanks for answer, All domains in the list has the same IP address, they're on the same IIS host. How does the datagroup should look like?
- Dmitry_Sherman
Nimbostratus
Another question, what to do if user typed the domain name without www ? Can I do a "contains" match instead of equal?
- Dmitry_Sherman
Nimbostratus
Where do I specify the node name?
- Kevin_Stewart
Employee
Hello thanks for answer, All domains in the list has the same IP address, they're on the same IIS host. How does the datagroup should look like?
Do you mean all of the domains resolve to the same IP address? Are you doing host-based redirection in IIS?
Another question, what to do if user typed the domain name without www ? Can I do a "contains" match instead of equal?
You can use "starts_with", "end_with", "contains", and "equals" in a class match.
Where do I specify the node name?
When you say "node name", what do you mean specifically? You stated that all of the domains are using a single IP, so that'd only be one node. In order to effective load balance these services, there needs to be some separation. If you're doing host-based redirection in IIS, then a separate load balancer isn't really doing anything for you since it's simply sending all traffic to a single IP address. Ultimately, you either want to separate these services by IP, or at the very least port. That way, should you ever need to use TWO servers to handle a given application, you can drop those into a pool and actually load balance and monitor them.
- Dmitry_Sherman
Nimbostratus
Hello, Yes, all hosts are on the same IP. This is exactly what I need.
I have total 2 hosts, I need to send all hosts that match the list to node1 and all other to the default node2.
Please help.
- Dmitry_Sherman
Nimbostratus
Totally there is 1000 domains, 500 of them hosted on server1 and 500 of them hosted on server2.
All domains resolves to F5's Virtual Server ip, therefore I need to route the first half to server1 and the second to server2.
- Kevin_Stewart
Employee
Then you just need to modify the data group to reflect that. Example:
"www.domain1.com" := "10.10.10.11 80" "www.domain2.com" := "10.10.10.11 80" "www.domain3.com" := "10.10.10.11 80" "www.domain4.com" := "10.10.10.11 80" ... "www.domain500.com" := "10.10.10.11 80" "www.domain501.com" := "10.10.10.12 80" "www.domain502.com" := "10.10.10.12 80" "www.domain503.com" := "10.10.10.12 80" "www.domain504.com" := "10.10.10.12 80" ... "www.domain1010.com" := "10.10.10.12 80"though I think at this point you should probably just use two pools:
"www.domain1.com" := "pool1" "www.domain2.com" := "pool1" "www.domain3.com" := "pool1" "www.domain4.com" := "pool1" ... "www.domain500.com" := "pool1" "www.domain501.com" := "pool2" "www.domain502.com" := "pool2" "www.domain503.com" := "pool2" "www.domain504.com" := "pool2" ... "www.domain1010.com" := "pool2"and then modify the iRule accordingly:
when HTTP_REQUEST { if { [class match [string tolower [HTTP::host]] equals my_domain_dg] } { pool [class match -value [string tolower [HTTP::host]] equals my_domain_dg] } } - BinaryCanary_19Historic F5 Account
I would add to Kevin Stewart's suggestion: Use an external data group, and use one datagroup for each class of domains. So if you are splitting into 2, one datagroup will contain 500 domains, the next datagroup will contain 500. Also use one pool for each class.
Use if-elseif expressions to match the classes as highlighted in Kevin's example.
Since you are matching domain names, you will need to match by HTTP::host, as that is independent of IP address.
Reference: Irules If and Expressions: https://devcentral.f5.com/articles/irules-101-02-if-and-expressions.UjG3LETK3Fg
- Kevin_Stewart
Employee
This is an interesting idea, but not sure what benefit it brings. The iRule would potentially have to parse two data groups to find a domain. - Dmitry_Sherman
Nimbostratus
Can you show an example please? - BinaryCanary_19Historic F5 AccountHe wants domains in one list to go to one pool, and the next set to go to a different pool. Using two datagroups seems like the easiest way to do this.
- Dmitry_Sherman
Nimbostratus
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.
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