Forum Discussion
Aidan_Carty_242
Nimbostratus
Jan 31, 2006Loadbalance redirects
Were migrating an internet application behind a BIGIP,
it has specfic url requirements so we have a simple iRule on a virtual server, all working fine.
rule redirect_to_webservers {
when HTTP_REQUEST {
HTTP::redirect https://www1.server.com
}
}
But this is putting a load on www1 server, would like todo the following
rule redirect_to_webserver {
when HTTP_REQUEST {
Pick a server 1 2 or 3 then {
case 1
HTTP::redirect https://www1.server.com
case 2
HTTP::redirect https://www2.server.com
case 3
HTTP::redirect https://www3.server.com
}
}
}
Can't figure out how i would make the iRule pick a server, something simple would do or maybe generate a random value based on the clients ip or date/time, then use this value to pick a server.
Any ideas ?
6 Replies
- Colin_Walker_12Historic F5 AccountWell, my first recommendation, if it's possible, would be to create a pool with the three systems in it, and just let BIG-IP load balance normally to that pool. You wouldn't need an iRule at all for this.
If, for some reason, you can't use a pool, and need the explicit redirect in the iRule, then you'd just need something like a simple counter to spread out the requests in a round robin fashion, like this:
*edited to include unruley's suggestion below*when RULE_INIT { set ::n 1 } when HTTP_REQUEST { if { $::n >= 4 } { set n 1 } HTTP::redirect "https://www$n.server.com" incr ::n }
-Colin - unRuleY_95363Historic F5 AccountBTW, you probably want a :: in front of n, so that it is in the global namespace.
- Aidan_Carty_242
Nimbostratus
Thanks Guys, see the below rule we put together...
rule lb_rule {
when RULE_INIT {
set ::lb_counter 1
log local0. "Rule Starting lb_counter is $::lb_counter"
}
when HTTP_REQUEST {
log local0. "HTTP Request counter is $::lb_counter"
if {$::lb_counter == 1} {
set ::lb_counter 2
log "Logging to server1"
HTTP::redirect "https://server1.f5.com"
}
elseif {$::lb_counter == 2} {
set ::lb_counter 3
log local0. "Logging to server2"
HTTP::redirect "https://server2.f5.com"
}
elseif {$::lb_counter == 3} {
set ::lb_counter 1
log local0. "Logging to server3"
HTTP::redirect "https://server3.f5.com"
}
}
} - Colin_Walker_12Historic F5 AccountNice work! I always enjoy seeing the result of the discussions here on DevCentral. Thanks for taking the time to come back and post your rule, it's much appreciated!
-Colin - Flavien_Vincent
Nimbostratus
Hello everyone.
First, I'm not belingual so excuse my English.
In my configuration, I have one pool named all_support_pool_fla and 4 servers. My goal is to share http and ftp traffic like this : two servers deal whith http traffic and two others deal whith ftp traffic. But all the servers are in the pool all_support_pool_fla.
Members of my_pool had been defined like that :
172.20.50.100:80
172.20.50.100:21
172.20.50.101:80
172.20.50.101:21
172.20.50.102:80
172.20.50.102:21
172.20.50.103:80
172.20.50.103:21
I want to create an iRule which can share traffic between them. I know this can be done easily by create two pools, but I like to make my life harder:P
By taking exemple on this iRule I made another one :
when RULE_INIT {
set ::compteur_http 1
set ::compteur_ftp 1
}
when HTTP_REQUEST {
if { [TCP::local_port] eq "80" } {
if { $::compteur_http == 1 } {
set ::compteur_http 2
pool all_support_pool_fla member 172.20.50.100:80
}
elseif { $::compteur_http == 2 } {
set ::compteur_http 1
pool all_support_pool_fla member 172.20.50.101:80
}
}
if { [TCP::local_port] eq "21" } {
if { $::compteur_ftp == 1 } {
set ::compteur_ftp 2
pool all_support_pool_fla member 172.20.50.102:21
}
elseif { $::compteur_ftp == 2 } {
set ::compteur_ftp 1
pool all_support_pool_fla member 172.20.50.103:21
}
}
}
But there is two problems. First, FTP traffic doesn't run. I think this is because I used this in a block with HTTP_REQUEST. Should I use CLIENT_ACCEPTED or something else?
And secondly this iRule is run each time a client connect to the virtual server, so every time the client is directed to the server 172.20.50.100 (for HTTP of course), and I want to use a load balancing like Round Robin (no more complication it's useless:D) in the iRule.
Please help me.
Thanks. - Deb_Allen_18Historic F5 AccountYou are correct that FTP will not function properly within an HTTP virtual server.
The good news is that the load balancing you want can be accomplished using built-in product features instead of a rule.
You'll need to create 2 pools, one containing just the webservers, the other containing just the ftp servers. Set the load balancing method to Round Robin for both.
Then create 2 virtual servers, one for HTTP on port 80 with an http profile applied and using the HTTP pool created above as the resource, and one for FTP on port 21 with an ftp profile applied and using the FTP pool created above.
You may need to add persistence and monitors to finalize the configuration, but that's the basic setup.
HTH
/deb
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects