Perlbal is fast and efficient web server, reverse proxy(load balancer). Here are quick steps to get started with it. I have tested perlbal-1.60 on my CentOS 5 box. There are many other possible ways to do the same and the way which worked for me, may not work for you.
Step 1. Download perlbal OR install it via perl cpan, like this:
# perl -MCPAN -e shell
cpan-> install perlbal
Step 2. Find out its sample config (/root/.cpan/build/Perlbal-1.60/doc/config-guide.txt) or if you downloaded and compiled it, file will be there. Put this file in /etc/perlbal as perlbal.conf.
# mkdir /etc/perlbal
# cp /root/.cpan/build/Perlbal-1.60/doc/config-guide.txt /etc/perlbal/perlbal.conf
Step 3. Update the perlbal.conf file as per your requirements.
for example, we are using it as load balancer, here is sample config
# vi /etc/perlbal/perlbal.conf
CREATE POOL my_apaches
SET nodefile = conf/nodelist.dat # IP of backend Apache servers.
CREATE SERVICE balancer
SET listen = 0.0.0.0:80
SET role = reverse_proxy
SET pool = my_apaches
SET persist_client = on
SET persist_backend = on
SET verify_backend = on
ENABLE balancer
# Keep an internal management port open to reconfigure pool automatically via telnet
CREATE SERVICE mgmt
SET role = management
SET listen = 127.0.0.1:60000
ENABLE mgmt
Step 4. Start perlbal module as daemon.
# perlbal -d
Step 5. Test by connecting through management port
# telnel 127.0.0.1 60000
Step 6. One major concern is that the backend servers will log entries with IP address of load balancer instead of actual user’s IP. To overcome this issue, install and configure mod_rpaf for apache at backend servers. Login in backend server and install the module:
# cd /usr/src/
# wget
# tar xzf mod_rpaf-0.6.tar.gz
# cd mod_rpaf-0.6
# apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
# vi /etc/httpd/conf/httpd.conf
LoadModule rpaf_module modules/mod_rpaf-2.0.so
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1 192.168.0.1 ## replace your IP of load balancer
RPAFheader X-Forwarded-For
# service httpd restart
Testing
Step 1. Create a simple perl file and put it in cgi-bin directory of all backend servers.
# vi /var/www/cgi-bin/test.pl
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print " Web server load balance testing ";
print "Web Server running fine.";
# Fetch IP of server
my $ifout =`ifconfig eth0 | grep inet`;
$ifout =~ m/\s+inet\saddr:([\d\.]+)\s.+/g;
print "This page is fetched from: $1 Server.";
Step 2. Start testing from browser and try to access the perl script from your load balancer server. Add more backends (by updating perlbal.conf) and test again. As per the load you will notice that perl script will be fetched from different back ends.
Adding / removing backends on the fly
Step 1. To maximum utilize the load balanced environment, there should be some technique by which backend servers can be added or removed on fly in the pool of perlbal as per the load. The topic of measuring load of backend servers and then making right decision is beyond the scope of this post. I developed some perl scripts to achieve the same in Amazon EC2[aws.amazon.com/ec2] environment, where we can create/remove servers on fly. If you are also on EC2, just post a comment or send mail to me and I will happily give scripts to you. Updating perlbal using a perl script with the help of Net::Telnet module is very easy. Here’s sample code:
use Net::Telnet;
$telnet=new Net::Telnet(Host=>$loadbalancerIP,Port=>60000,Timeout=>20, Errmode=>'Die');
$telnet->print("pool my_apaches add $newserverIP");
$telnet->waitfor('/OK/i');
$telnet->close;
Its Done. Play with it. One of the noticed minus point (as of ver 1.60), perlbal is not so efficient/capable while handling https connections. In case you have website which doesnt require https connections, perlbal should be given preferrence.
Other useful links:
1. Load balancing definition.
1. LVS
2. Mod_Proxy in Apache
3. Pound
4. Balance
阅读(852) | 评论(0) | 转发(0) |