<?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; haproxy</title>
	<atom:link href="http://linuxadminzone.com/tag/haproxy/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>
	</channel>
</rss>

