<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux Admin Zone &#187; perlbal</title>
	<atom:link href="http://linuxadminzone.com/tag/perlbal/feed/" rel="self" type="application/rss+xml" />
	<link>http://linuxadminzone.com</link>
	<description>Adding more reasons to celebrate Open Source.</description>
	<lastBuildDate>Wed, 09 May 2012 10:17:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Download, install and configure perlbal to load balance web server</title>
		<link>http://linuxadminzone.com/download-install-and-configure-perlbal-to-load-balance-web-server/</link>
		<comments>http://linuxadminzone.com/download-install-and-configure-perlbal-to-load-balance-web-server/#comments</comments>
		<pubDate>Tue, 20 May 2008 10:24:58 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[Load Balancer]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[load balance]]></category>
		<category><![CDATA[perlbal]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=12</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.danga.com/perlbal/">Perlbal</a> 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.</p>
<p>Step 1. <a href="http://code.google.com/p/perlbal/">Download perlbal</a> OR install it via perl cpan, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-MCPAN</span> <span style="color: #660033;">-e</span> shell
cpan-<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #c20cb9; font-weight: bold;">install</span> perlbal</pre></div></div>

<p>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.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>perlbal
$ <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.cpan<span style="color: #000000; font-weight: bold;">/</span>build<span style="color: #000000; font-weight: bold;">/</span>Perlbal-<span style="color: #000000;">1.60</span><span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>config-guide.txt <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>perlbal<span style="color: #000000; font-weight: bold;">/</span>perlbal.conf</pre></div></div>

<p>Step 3. Update the perlbal.conf file as per your requirements.<br />
for example, we are using it as load balancer, here is sample config</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>perlbal<span style="color: #000000; font-weight: bold;">/</span>perlbal.conf
CREATE POOL my_apaches
SET nodefile = conf<span style="color: #000000; font-weight: bold;">/</span>nodelist.dat  <span style="color: #666666; font-style: italic;"># IP of backend Apache servers.</span>
&nbsp;
CREATE SERVICE balancer
SET listen          = 0.0.0.0:<span style="color: #000000;">80</span>
SET role            = reverse_proxy
SET pool            = my_apaches
SET persist_client  = on
SET persist_backend = on
SET verify_backend  = on
ENABLE balancer
&nbsp;
<span style="color: #666666; font-style: italic;"># Keep an internal management port open to reconfigure pool automatically via telnet</span>
CREATE SERVICE mgmt
SET role   = management
SET listen = 127.0.0.1:<span style="color: #000000;">60000</span>
ENABLE mgmt</pre></div></div>

<p>Step 4. Start perlbal module as daemon.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ perlbal <span style="color: #660033;">-d</span></pre></div></div>

<p>Step 5. Test by connecting through management port</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ telnel 127.0.0.1 <span style="color: #000000;">60000</span></pre></div></div>

<p>Step 6. One major concern is that the backend servers will log entries with IP address of load balancer instead of actual user&#8217;s IP. To overcome this issue, install and configure mod_rpaf for apache at backend servers. Login in backend server and install the module:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>stderr.net<span style="color: #000000; font-weight: bold;">/</span>apache<span style="color: #000000; font-weight: bold;">/</span>rpaf<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>mod_rpaf-<span style="color: #000000;">0.6</span>.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> xzf mod_rpaf-<span style="color: #000000;">0.6</span>.tar.gz
$ <span style="color: #7a0874; font-weight: bold;">cd</span> mod_rpaf-<span style="color: #000000;">0.6</span>
$ apxs <span style="color: #660033;">-i</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">-n</span> mod_rpaf-<span style="color: #000000;">2.0</span>.so mod_rpaf-<span style="color: #000000;">2.0</span>.c
$ <span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>httpd.conf
LoadModule rpaf_module modules<span style="color: #000000; font-weight: bold;">/</span>mod_rpaf-<span style="color: #000000;">2.0</span>.so
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1 192.168.0.1  <span style="color: #666666; font-style: italic;">## replace your IP of load balancer</span>
RPAFheader X-Forwarded-For
&nbsp;
$ service httpd restart</pre></div></div>

<p><strong>Testing</strong></p>
<p>Step 1. Create a simple perl file and put it in cgi-bin directory of all backend servers.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;">/</span>test.pl
<span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
print <span style="color: #ff0000;">&quot;Content-Type: text/html<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
print <span style="color: #ff0000;">&quot; Web server load balance testing &quot;</span>;
print <span style="color: #ff0000;">&quot;Web Server running fine.&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;"># Fetch IP of server</span>
my <span style="color: #007800;">$ifout</span> =<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span> eth0 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> inet<span style="color: #000000; font-weight: bold;">`</span>;
<span style="color: #007800;">$ifout</span> =~ m<span style="color: #000000; font-weight: bold;">/</span>\s+inet\saddr:<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>\d\.<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>\s.+<span style="color: #000000; font-weight: bold;">/</span>g;
&nbsp;
print <span style="color: #ff0000;">&quot;This page is fetched from: $1 Server.&quot;</span>;</pre></div></div>

<p>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.</p>
<p><strong>Adding / removing backends on the fly</strong></p>
<p>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&#8217;s sample code:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">Telnet</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$telnet</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> Net<span style="color: #339933;">::</span><span style="color: #006600;">Telnet</span><span style="color: #009900;">&#40;</span>Host<span style="color: #339933;">=</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span><span style="color: #0000ff;">$loadbalancerIP</span><span style="color: #339933;">,</span>Port<span style="color: #339933;">=</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span><span style="color: #cc66cc;">60000</span><span style="color: #339933;">,</span>Timeout<span style="color: #339933;">=</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> Errmode<span style="color: #339933;">=</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span><span style="color: #ff0000;">'Die'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$telnet</span><span style="color: #339933;">-</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span>print<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;pool my_apaches add $newserverIP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$telnet</span><span style="color: #339933;">-</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span>waitfor<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/OK/i'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$telnet</span><span style="color: #339933;">-</span><span style="color: #0000ff;">&amp;gt</span><span style="color: #339933;">;</span>close<span style="color: #339933;">;</span></pre></div></div>

<p>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.</p>
<p>An alternate to perlbal is haproxy load balancer, I&#8217;ve covered it <a href="http://linuxadminzone.com/install-and-configure-haproxy-the-software-based-loadbalancer-in-ubuntu/">here</a>, <a href="http://linuxadminzone.com/how-to-install-setup-and-config-haproxy-loadbalancer-for-content-switching/">here</a> and <a href="http://linuxadminzone.com/enable-or-fix-logging-for-haproxy-load-balancer/">here</a> as well. </p>
<p>You may also like to read:</p>
<p>* <a href="http://linuxadminzone.com/install-and-configure-haproxy-the-software-based-loadbalancer-in-ubuntu/">Install and configure haproxy load balancer</a>, lightweight and fast alternative of perlbal/apache proxy.<br />
* <a href="http://linuxadminzone.com/enable-or-fix-logging-for-haproxy-load-balancer/">Enable or fix logging for Haproxy or perlbal load balancer.</a><br />
* <a href="http://linuxadminzone.com/how-to-install-setup-and-config-haproxy-loadbalancer-for-content-switching/">Install and setup haproxy load balancer for content switching.</a><br />
* <a href="http://linuxadminzone.com/5-steps-to-secure-your-linux-server/"> 5 steps to secure your Linux Server </a><br />
* <a href="http://linuxadminzone.com/ensuring-secure-access-to-production-linux-servers/"> Ensuring secure access to production Linux Servers </a><br />
* <a href="http://linuxadminzone.com/bash-script-to-backup-essential-log-files-of-linux-server/"> Bash script to backup essential log files in Linux </a> </p>
]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/download-install-and-configure-perlbal-to-load-balance-web-server/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

