Forum Moderators: phranque

Message Too Old, No Replies

Help regarding load balancing perl script of apache server

         

enjoystar

8:04 am on Apr 13, 2006 (gmt 0)

10+ Year Member



Hi,
I am using apache web server 1.3 and performed load balancing using rewrite module which invokes lb.pl script where the back end servers are apache web servers and the front end server is also an apache server.

The above load balancing i did using URL such as
http://www.example.com. Therefore whenever user enter the same URL the control goes to backend server such as [www1.example.com....]

Now instead of using the domain name i want to use ip address for accessing the site.
ex: [10.1.1.1:8080...]
So i modified the lb.pl script and created the array for the ip address and the script returns an URl such as [10.1.1.2...] instead of [www1.example.com....]

The problem is when i use the above perl script and enter the URL request such as [10.1.1.1:8080...] in the browser i get a bad request for the 1st time and for the second time the request goes to the back end server once again i enter the request i get the bad request and again for the next request its successful
Therefore alternately i get a bad request and successful request.

Please anyone know why the above thing happens
the modified lb.pl script is as follows::

#!/usr/bin/perl
### lb.pl -- load balancing script

$¦ = 1;

## Variables Initialization ##

$first = 0; # the first server (not 0 here, because 0 is myself)
$last = 4; # the last server in the round-robin

## IP Addresses of back end servers ##
@arrayname = ("10.4.2.75", "10.4.1.74","10.4.1.74","10.4.2.75","10.4.2.75");

$cnt = 0; # counter
print "*** Load Balancing ***\n";

while (<STDIN>)
{
print "Counter:$cnt\n";

$cnt = (($cnt+1) % ($last+1-$first));
$ipaddress = $arrayname[$cnt];
$server = sprintf("%s",$ipaddress );
print "http://$server/$_";
}

##EOF##

Thanks