Forum Discussion
kyn3s_53106
Nimbostratus
Feb 03, 2010Loadbalancing URI on same server ?
Hello folks !
I have an unusual request to submit to your skills. I have two web servers running a proprietary solution. For some dark reasons (process loadbalancing, process optimisation...), they both are running two identical websites on same port but different URI. This is as follows:
http://1.2.3.45:8080/toto1.exe
http://1.2.3.45:8080/toto2.exe
http://1.2.3.46:8080/toto1.exe
http://1.2.3.46:8080/toto2.exe
I would like the users to access each of them. So I wrote the following iRule, as I could see in another post (http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&tpage=1&view=topic&postid=6232).
I am actually unable to test this solution. So any help is appreciated. My questions are:
Would this work ?
Is there any way to optimize this ?
How about using a pool ?
And what about client-server affinity ?
Thanks again!
rule lb_URI_rule {
when RULE_INIT {
set ::lb_caisd_counter 1
}
when HTTP_REQUEST {
if {$::lb_caisd_counter == 1} {
set ::lb_caisd_counter 2
HTTP::redirect "http://1.2.3.45:8080/toto1.exe "
}
elseif {$::lb_caisd_counter == 2} {
set ::lb_caisd_counter 3
HTTP::redirect "http://1.2.3.46:8080/toto1.exe "
}
elseif {$::lb_caisd_counter == 3} {
set ::lb_caisd_counter 4
HTTP::redirect "http://1.2.3.45:8080/toto2.exe "
}
elseif {$::lb_caisd_counter == 4} {
set ::lb_caisd_counter 1
HTTP::redirect "http://1.2.3.46:8080/toto2.exe "
}
}
}12 Replies
- The_Bhattman
Nimbostratus
Hi kyn3s,
Is 1.2.3.45 and 1.2.3.46 a virtual service or a IP address of a node?
Thanks,
Bhattman - kyn3s_53106
Nimbostratus
Hi Bhattman,
They are nodes.
Actually, when requesting a single virtual service, I would like the users to be redirected to on of the 4 URL. Hope there's a simple way to do it that would take client-server affinity into account.
Thank you btw,
-kyn3s. - The_Bhattman
Nimbostratus
Sounds you want them to hit the sites on different URIs in a round robin fashion. Is that correct?
Bhattman - kyn3s_53106
Nimbostratus
Correct! Least Conn would be better but probably much harder using iRules...
2 nodes in my pool but 4 URL to access!
-kyn. - The_Bhattman
Nimbostratus
Hi Kyn,
In that your original code is pretty close to what you wanted
However, here is a slight alteration:
You would create a default pool containing the 2 webservers listening on port 8080. You can set that as least connections.
The followingwhen RULE_INIT { set ::rr_counter 0 } when HTTP_REQUEST { if {[HTTP::host] eq "www.yourapp.com" and [HTTP::uri] eq "/" } Check the counter value switch $::rr_counter { 0 { HTTP::redirect "http://[HTTP::host]/toto1.exe set ::rr_counter 1 } 1 { HTTP::redirect "http://[HTTP::host]/toto2.exe set ::rr_counter 0 } } } }
The thought here is that when the clients come to the virtual server for the first time he/she or a device will first be given either toto1.exe or toto2.exe. When client is redirect back, the Load balalncing algorithm (in your case least connections) and forward it to one of the 2 servers in the pool containing either toto1.exe ro toto2.exe URI.
This is untested but I think it might help
Bhattman - hoolio
Cirrostratus
You can't really do true least connections load balancing if the connections for the majority of the full session are going direct from the clients to the servers.
Bhattman's latest example would redirect the clients back to the VIP and allow you to do least connections. This wouldn't be direct connections from the clients to the servers. You'd also need to handle persistence in addition to the iRule. This could be done using a source or cookie insert persistence profile.
Aaron - The_Bhattman
Nimbostratus
Good point Aaron.
Bhattman - kyn3s_53106
Nimbostratus
Thank you for your code Bhattman. Thank for helping too Aaron.
I may have not been clear enough, though. Or I need some rest as I am not sure Aaron meant what I am looking for. I am kinda new to F5 too and dont know much abou it yet.
Here is the point: users will hit a virtual service, let's say http://10.10.10.10/ (IP address). I would like them to be redirected to my nodes, on 2 different URI each time:
- http://1.2.3.45:8080/foo.exe
- http://1.2.3.45:8080/bar.exe
- http://1.2.3.46:8080/foo.exe
- http://1.2.3.45:8080/bar.exe
In my understanding, using your code, I would be redirected to:
- http://10.10.10.10/foo.exe
- http://10.10.10.10/bar.exe
wouldn't I?
Unless 10.10.10.10 redirects to 1 of my 2 nodes listening on 8080 and the path is kept. Can you tell me whether its the case or not?
That may even be better as it would mask the nodes IP...
-kyn. - The_Bhattman
Nimbostratus
Hi Kyn,
That's correct that the code I posted would basically take you to either foo.exe or bar.exe. However, you can't send the same client request to 2 nodes at the same time.
Bhattman - kyn3s_53106
Nimbostratus
Hi Bhattman! Then we agree. My english lacks practicing! Will try your solution asap and hopefully give you a positive feedback!
Thank you again for helping so quickly! Great forum ;-)
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