<?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 balance</title>
	<atom:link href="http://linuxadminzone.com/tag/load-balance/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>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>

