<?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; Load Balancer</title>
	<atom:link href="http://linuxadminzone.com/category/load-balancer/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>install and configure haproxy, the software based loadbalancer in Ubuntu</title>
		<link>http://linuxadminzone.com/install-and-configure-haproxy-the-software-based-loadbalancer-in-ubuntu/</link>
		<comments>http://linuxadminzone.com/install-and-configure-haproxy-the-software-based-loadbalancer-in-ubuntu/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 16:39:32 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[Load Balancer]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=293</guid>
		<description><![CDATA[HAProxy is a very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It&#8217;s free and open source application which is very lightweight as well. I checked few other alternatives like perlbal, pond etc. but found haproxy most competent performer. I&#8217;m describing here the steps I followed to [...]]]></description>
			<content:encoded><![CDATA[<p>HAProxy is a very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It&#8217;s free and open source application which is very lightweight as well. I checked few other alternatives like perlbal, pond etc. but found haproxy most competent performer. </p>
<p>I&#8217;m describing here the steps I followed to download, install and configure it in Ubuntu Server. We have 2 backend Web servers which will receive traffic from Load balancer host running HAProxy in front of them. </p>
<p><strong>Step 1.</strong> Download, compile and install HAproxy from <a href="http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.11.tar.gz">here</a> :</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: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>haproxy.1wt.eu<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.4</span><span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>haproxy-1.4.11.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> xzf haproxy-1.4.11.tar.gz 
$ <span style="color: #7a0874; font-weight: bold;">cd</span> haproxy-1.4.11
$ <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>You can find an example of config file in /usr/src/haproxy-1.4.11/examples/haproxy.cfg which you copy in /etc/haproxy and update it per your requirement. </p>
<p><strong>Step 2.</strong> Update config file per your requirements:</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>haproxy
$ <span style="color: #c20cb9; font-weight: bold;">cp</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>haproxy-1.4.11<span style="color: #000000; font-weight: bold;">/</span>examples<span style="color: #000000; font-weight: bold;">/</span>haproxy.cfg <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>haproxy
$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>haproxy</pre></div></div>

<p>you can see configs I used for our server below:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> haproxy.cfg
global
        log 127.0.0.1  local0
        log 127.0.0.1  local1 notice
        log loghost    local0 info
        maxconn <span style="color: #000000;">4096</span>
        uid <span style="color: #000000;">99</span>
        gid <span style="color: #000000;">99</span>
        daemon
        <span style="color: #666666; font-style: italic;">#debug</span>
        <span style="color: #666666; font-style: italic;">#quiet</span>
&nbsp;
defaults
        log    global
        mode    http
        option httplog
        option dontlognull
        retries <span style="color: #000000;">3</span>
        option redispatch
        maxconn <span style="color: #000000;">2000</span>
        contimeout      <span style="color: #000000;">5000</span>
        clitimeout      <span style="color: #000000;">50000</span>
        srvtimeout      <span style="color: #000000;">50000</span>
&nbsp;
listen  web-service 0.0.0.0:<span style="color: #000000;">80</span>
        option forwardfor
        option httpchk OPTIONS <span style="color: #000000; font-weight: bold;">/</span>health_check.html
        stats <span style="color: #7a0874; font-weight: bold;">enable</span>
        stats refresh 10s
        stats hide-version
        stats scope   .
        stats uri     <span style="color: #000000; font-weight: bold;">/</span>lb?stats
        stats realm   LB2\ Statistics
        stats auth    admin:Adm1nn
&nbsp;
        server  web1 <span style="color: #000000;">10</span>.x.x.x:<span style="color: #000000;">80</span> check inter <span style="color: #000000;">2000</span> fall <span style="color: #000000;">3</span>
        server  web2 <span style="color: #000000;">10</span>.x.x.x:<span style="color: #000000;">80</span> check inter <span style="color: #000000;">2000</span> fall <span style="color: #000000;">3</span></pre></div></div>

<p>Most important section in this config file is &#8220;listen&#8221; where we have several important options. Few are related to display stats and in the end there are entries of backend web server which actually serves the traffic. </p>
<p>I&#8217;ve used most of default options and update it little bit to accommodate my requirements. There&#8217;s lots of optimization needed and therefore this can be called as a bare configuration. I would write about further enhancements later after some more experiments. </p>
<p>Because backend web servers receive traffic from Load balancer so in usual case they will see IP address of Load balancer itself instead of real user, I&#8217;ve written <a href="http://linuxadminzone.com/enable-or-fix-logging-for-haproxy-load-balancer/">a post</a> earlier to fix this. </p>
<p>You can also use HAProxy to do content switching where it will divert traffic amoung several backend servers available based on specified conditions, I&#8217;ve written a <a href="http://linuxadminzone.com/how-to-install-setup-and-config-haproxy-loadbalancer-for-content-switching/">detailed post</a> on this topic earlier. </p>
<p><strong>Step 3.</strong> Start the daemon:<br />
After initial config, you can start daemon and check things. Let&#8217;s check syntax first:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ haproxy <span style="color: #660033;">-c</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>haproxy<span style="color: #000000; font-weight: bold;">/</span>haproxy.cfg</pre></div></div>

<p>If no issues in config, let&#8217;s start he process:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ haproxy <span style="color: #660033;">-f</span> haproxy.cfg</pre></div></div>

<p>HAProxy is started, you can quickly check its status page at http://your-lb-ip/lb?status where you need to supply user and password as per we specified in config file.</p>
<p>You can keep updating your config file and reload the haproxy service without having to stop/start it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ haproxy <span style="color: #660033;">-f</span> haproxy <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>haproxy.pid <span style="color: #660033;">-st</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>haproxy.pid<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/install-and-configure-haproxy-the-software-based-loadbalancer-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Enable or fix logging for HAProxy load balancer</title>
		<link>http://linuxadminzone.com/enable-or-fix-logging-for-haproxy-load-balancer/</link>
		<comments>http://linuxadminzone.com/enable-or-fix-logging-for-haproxy-load-balancer/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 07:01:15 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[Load Balancer]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[haproxy logs]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=90</guid>
		<description><![CDATA[After configuration of HAProxy to balance web traffic, I&#8217;ve noticed that HAProxy is not generating any logs in my server. Due to its load balancer role, logging is vital to diagnose any issue that might come in future. In its default config, HAProxy send logs to a syslog facility: local0, via a socket connection. By [...]]]></description>
			<content:encoded><![CDATA[<p>After configuration of <a href="http://linuxadminzone.com/install-and-configure-haproxy-the-software-based-loadbalancer-in-ubuntu/">HAProxy</a> to balance web traffic, I&#8217;ve noticed that HAProxy is not generating any logs in my server. Due to its load balancer role, logging is vital to diagnose any issue that might come in future. </p>
<p>In its default config, HAProxy send logs to a syslog facility: local0, via a socket connection. By default, your syslog configuration probably doesn’t accept socket connections, and even doesn’t have a local0 facility, so you have no HAProxy log. If you want it, configure syslog to accept TCP connections by adding -r to syslogd parameters.</p>
<p>On a RedHat/CentOS server, edit the value of SYSLOGD_OPTIONS in /etc/sysconfig/syslog:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SYSLOGD_OPTIONS</span>=<span style="color: #ff0000;">&quot;-m 0 -r&quot;</span></pre></div></div>

<p>On a Debian/Ubuntu server, edit the value of SYSLOGD in /etc/default/syslogd:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SYSLOGD</span>=<span style="color: #ff0000;">&quot;-r&quot;</span></pre></div></div>

<p>Then set up syslog facility local0 and direct it to file /var/log/haproxy.log or your desired location by editing /etc/syslog.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">local0.<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>haproxy.log</pre></div></div>

<p>finally, restart syslog service to apply changes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>syslog restart</pre></div></div>

<p>You can see that HAProxy logging is started.</p>
<p>Other useful article on this blog that you may like to read:<br />
* <a href="http://linuxadminzone.com/how-to-install-setup-and-config-haproxy-loadbalancer-for-content-switching/">Configure HAProxy for content switching</a><br />
* <a href="http://linuxadminzone.com/5-steps-to-secure-your-linux-server/">5 Steps to secure your Production Linux Server</a><br />
* <a href="http://linuxadminzone.com/ensuring-secure-access-to-production-linux-servers/">Ensuring secure access to your Production Linux Server</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 Server</a></p>
]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/enable-or-fix-logging-for-haproxy-load-balancer/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to Install, setup and config HAProxy loadbalancer for content switching</title>
		<link>http://linuxadminzone.com/how-to-install-setup-and-config-haproxy-loadbalancer-for-content-switching/</link>
		<comments>http://linuxadminzone.com/how-to-install-setup-and-config-haproxy-loadbalancer-for-content-switching/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 13:54:36 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Load Balancer]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[haproxy]]></category>
		<category><![CDATA[load balance]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=23</guid>
		<description><![CDATA[First here is the guide I have written to install and configure HAproxy. Next, Sometimes we have different servers with different contents, such as one set of servers with all static contents (html, image files) of a website while another set of servers have dynamic contents (cgi, perl, php scripts) This type of config is [...]]]></description>
			<content:encoded><![CDATA[<p>First <a href="http://linuxadminzone.com/install-and-configure-haproxy-the-software-based-loadbalancer-in-ubuntu/">here</a> is the guide I have written to install and configure HAproxy. Next, Sometimes we have different servers with different contents, such as one set of servers with all static contents (html, image files) of a website while another set of servers have dynamic contents (cgi, perl, php scripts) This type of config is beneficial in some situations where you want to serve your static data directly from CDN for faster response and dynamic contents from your own servers.</p>
<p>While deploying a load balancer, we need some mechanism to inform loadbalancer to forward request to different set of servers based on the condition specified. Here I&#8217;m using <a href="http://haproxy.1wt.eu/">HAProxy</a> load balancer on CentOS 5 box. This is a very small test setup in Amazon EC2 environment having 3 small instances.</p>
<p>Let&#8217;s start the action. Login to server where you want to install HAProxy. Download it and extract it. You can download source and compile but as its a single executable file, I prefer to download precompiled file for being lazy <img src='http://linuxadminzone.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </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>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>haproxy
$ <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>local<span style="color: #000000; font-weight: bold;">/</span>haproxy
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>haproxy.1wt.eu<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.3</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>haproxy-1.3.15.2-pcre-40kses-splice-linux-i586.notstripped.gz
$ <span style="color: #c20cb9; font-weight: bold;">gunzip</span> haproxy-1.3.15.2-pcre-40kses-splice-linux-i586.notstripped.gz
$ <span style="color: #c20cb9; font-weight: bold;">mv</span> haproxy-1.3.15.2-pcre-40kses-splice-linux-i586.notstripped haproxy
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> haproxy</pre></div></div>

<p>As an example, we have two backend servers/domains, one to serve static contents and other for dynamic contents. Let&#8217;s create config file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">vi</span> haproxy.cfg
&nbsp;
  defaults
    balance roundrobin
    cookie SERVERID insert indirect<span style="color: #000000; font-weight: bold;">&lt;/</span>code<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
  frontend www 10.252.130.162:<span style="color: #000000;">80</span>
    mode http
    acl dyn_content url_sub cgi-bin
    use_backend dyn_server <span style="color: #000000; font-weight: bold;">if</span> dyn_content
    default_backend stat_server
&nbsp;
  backend dyn_server
    mode http
    server dserver1 dynamic.example.com:<span style="color: #000000;">80</span> cookie A check
&nbsp;
backend stat_server
    mode http
    server sserver1 static.example.com:<span style="color: #000000;">80</span> cookie B check<span style="color: #000000; font-weight: bold;">&lt;/</span>code<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Here, 10.252.130.162 is the IP of your load balancer server. HAProxy configuration file has several sections called defaults, listen, frontend and backend. We used cookie to forward all subsequent requests from same user to same backend. The main thing here is the acl in frontend section which stats that if there&#8217;s a word &#8220;cgi-bin&#8221; in user&#8217;s url then use dyn_server as backend otherwise use default backend which is stat_server. You should refer <a href="http://haproxy.1wt.eu/#docs">HAProxy documentation</a> for further information of configurations.</p>
<p>Save the file and check it for syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>haproxy <span style="color: #660033;">-f</span> .<span style="color: #000000; font-weight: bold;">/</span>haproxy.cfg <span style="color: #660033;">-c</span></pre></div></div>

<p>It will throw warnings regarding missing timeouts in sections, you can ignore these warnings. If there&#8217;s any error, check the config file again.</p>
<p>Run HAProxy:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>haproxy3 <span style="color: #660033;">-f</span> .<span style="color: #000000; font-weight: bold;">/</span>haproxy.cfg <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>haproxy.pid</pre></div></div>

<p>Put load balancer&#8217;s public IP/domain name in your browser and test this setup, it should go as expected.</p>
<p>You may also like to read:<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><br />
* <a href="http://linuxadminzone.com/quickly-change-your-ssh-port-from-default-22-to-something-higher/"> Quickly change your ssh port from defualt 22 to something higher </a><br />
* <a href="http://linuxadminzone.com/ssh-port-forwarding-from-remote-to-local-machine/"> SSH port forwarding from remote to local machine </a><br />
* <a href="http://linuxadminzone.com/save-root-or-user-history-to-check-later/"> Save root or user history to check later </a><br />
* <a href="http://linuxadminzone.com/install-and-configure-denyhost/"> Install and configure denyhost to prevent brute force attacks </a></p>
]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/how-to-install-setup-and-config-haproxy-loadbalancer-for-content-switching/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<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>

