<?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>Abbas &#124; Bassu &#187; ipvsadm and ldirectord on centos5</title>
	<atom:link href="http://bashukhan.com/tag/ipvsadm-and-ldirectord-on-centos5/feed/" rel="self" type="application/rss+xml" />
	<link>http://bashukhan.com</link>
	<description>Life&#039;s having zeros and ones all over</description>
	<lastBuildDate>Thu, 29 Jul 2010 13:00:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>HA LB Cluster on CentOS5 &#8211; Without actual heartbeat :P</title>
		<link>http://bashukhan.com/ha-lb-cluster-on-centos5-without-actual-heartbeat-p/</link>
		<comments>http://bashukhan.com/ha-lb-cluster-on-centos5-without-actual-heartbeat-p/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 18:13:19 +0000</pubDate>
		<dc:creator>Abbas</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[centos5 cluster]]></category>
		<category><![CDATA[ha lb cluster with ipvsadm an heartbeat-ldirectord without actual "heartbeat"]]></category>
		<category><![CDATA[ipvsadm and ldirectord on centos5]]></category>
		<category><![CDATA[old load balance cluster centos5]]></category>
		<category><![CDATA[quick dirty centos5 apache load balance cluster]]></category>

		<guid isPermaLink="false">http://bashukhan.com/?p=118</guid>
		<description><![CDATA[Last month I wrote a howto for highly available load balanced Piranha cluster using Red Hat&#8217;s cluster suite. Until then it was quite not obvious why one should use the Debian styled network load balanced cluster in the production environment when actual &#8220;heartbeat&#8221; package and service creates a lot of havoc on Red Hat machines. [...]]]></description>
			<content:encoded><![CDATA[<p>Last month I <a href="http://bashukhan.com/tag/piranha-tutorial/" target="_blank">wrote a howto</a> for highly available load balanced Piranha cluster using Red Hat&#8217;s cluster suite. Until then it was quite not obvious why one should use the Debian styled network load balanced cluster in the production environment when actual &#8220;heartbeat&#8221; package and service creates a lot of havoc on Red Hat machines. But my reckoning of doing classic things more manually kept me interrogative and I found the flexible way of doing load balanced clustering without needing the actual heartbeat service. Reasons why I&#8217;m so much against of having it are numerous:<br />
- Running heartbeat snatches the independence of managing virtual IP addresses on load balancer by hand.<br />
- Thus restricting expansion of the pools!<br />
- Ldirector&#8217;s daemon must be managed by heartbeat when its running.<br />
- Waste of resources in utilization; such with a sheer restart of heartbeat service and it just sits on waiting and waiting,&#8230;<br />
- And above all, I don&#8217;t need a &#8220;second&#8221; load balancer for a failover. All that glitters is one load balancer running ldirectord in a simple environment and as for the job, it does most of heartbeat&#8217;s when acting as a divider and a monitor for distributing requests between web servers.</p>
<p><strong><em>Environment</em><br />
</strong></p>
<p>Requirements: At least three systems, each with a minimum of one IP (CentOS in my case). Packages &#8216;heartbeat&#8217;, &#8216;heartbeat-ldirector&#8217; for <a href="http://www.linux-ha.org/" target="_blank">load balancing</a> and &#8216;ipvsadm&#8217; for Linux <a href="http://www.linuxvirtualserver.org/" target="_blank">IP Virtual Server</a>. I know you&#8217;re thinking that why the &#8216;heartbeat&#8217; when actually we&#8217;re not going to run it. In fact, we&#8217;re not going to run it; its just for a dependency resolution, rather a service startup requirement &#8211; I should say (/etc/ha.d/shellfuncs is the file needed)! And I swear we won&#8217;t run it <img src='http://bashukhan.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ! So these are the packages which shape into a project <a href="http://www.ultramonkey.org/" target="_blank">Ultramonkey</a> when combined and it describes the different topologies of a functional HA LB cluster but that&#8217;s not our concern, anyway <img src='http://bashukhan.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  (perhaps yours if you think you&#8217;ve a bit of free time)</p>
<p>Virtual IP<strong>: </strong>10.10.10.60<br />
Load Balancer: 10.10.10.61 aka VM1.<br />
Cluster Nodes/Real Servers:<br />
Web Server1: 10.10.10.62 aka VM2<br />
Web Server2: 10.10.10.63 aka VM3.</p>
<p>And we&#8217;ll be using LVS-DR (direct routing) approach for clustering; its most widely used and has lesser downsides.<br />
Lets start by configuring the web servers first.</p>
<p><em><strong>Cluster Nodes  Configurations</strong></em></p>
<p><strong>1. </strong>On both web servers VM2 and VM3, apache should be running having a common serving file (for purpose of get checked by ldirectord).</p>
<pre class="brush: bash;">
# yum install httpd -y
# echo foo &gt; /var/www/html/test.html
# service httpd start
# chkconfig httpd on
</pre>
<p>And to distinguish both of the web servers during test loading, create at least a one unique file on each of web servers.</p>
<pre class="brush: bash;">
[root@VM2 ~]# echo &quot;This is VM2&quot; &gt; /var/www/html/index.html
[root@VM3 ~]# echo &quot;This is VM3&quot; &gt; /var/www/html/index.html
</pre>
<p><strong>2.</strong> Virtual IP needs to be terminated on both web servers so we&#8217;ll create a second network interface on each of it. Because eventually all three NICs on all three servers would have to have the same VIP so this would cause a problem with ARP as it resolves MACs against IPs. There are different solutions to this problem. Some may refer to use iptables or arptables_jf. Many would recommend changing default gateway route or hiding the network interface (by the way don&#8217;t use iptables or change default gateway for this; Red Hat discourages both of these methods as they cause a lot of overhead). But the most flexible approach I&#8217;ve found is:</p>
<p style="padding-left: 30px;"><strong>a. </strong>create a loopback interface so it doesn&#8217;t communicate with your network gateway/router directly.<br />
<strong>b.</strong> instruct Linux kernel to announce ARP requests with preference to be taken from local address when matching for communication instead preference from the destination address.<br />
<strong>c. </strong>instruct Linux kernel to send ARP responses only to the requests originating from same sender address to same local addresses&#8217; subnet. Details <a href="http://kb.linuxvirtualserver.org/wiki/Using_arp_announce/arp_ignore_to_disable_ARP" target="_blank">here</a>, if you&#8217;re really curious about it.</p>
<pre class="brush: bash;">
# vi /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
IPADDR=10.10.10.60
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback
#
# vi /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
# sysctl -p
# ifup lo:0
</pre>
<p><em><strong>Load Balancer Configuration</strong></em></p>
<p>We&#8217;ll be going through:</p>
<p><strong>a. </strong>installing required packages<br />
<strong>b.</strong> enabling IP forwarding,</p>
<pre class="brush: bash;">
# yum install heartbeat heartbeat-ldirector ipvsadm -y
# chkconfig --add ldirectord
# chkconfig --del heartbeat
# sed -i 's/net.ipv4.ip_forward = 1/net.ipv4.ip_forward = 0' /etc/sysctl.conf

# sysctl -p
</pre>
<p><strong>c.</strong> configure secondary eth0 for VIP as its going to be exposed to outside world or your local gateway and</p>
<pre class="brush: bash;">
# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
BOOTPROTO=none
ONBOOT=yes
HWADDR=3a:5d:71:ad:67:47
NETMASK=255.255.255.0
IPADDR=10.10.10.60
GATEWAY=12.12.12.1
TYPE=Ethernet
</pre>
<p><strong>d.</strong> then creating ldirector.cf, the configuration file of our load balancer, respectively!!</p>
<pre class="brush: bash;">
# vi /etc/ha.d/ldirectord.cf
checktimeout=10
checkinterval=2
autoreload=no
logfile=&quot;/var/log/ldirectord.log&quot;
quiescent=no
virtual=10.10.10.60:80
 real=10.10.10.62:80 gate
 real= 10.10.10.63:80 gate
 service=http
 request=&quot;test.html&quot;
 receive=&quot;foo&quot;
 scheduler=wrr
 protocol=tcp
 checktype=negotiate

# service ldirectord start
</pre>
<p>Option &#8216;quiescent&#8217; just removes the real server from ipvs table whom ldirectord doesn&#8217;t recieve any response from, when querying for test.html within ten seconds, marking that real server as dead; until its available again. Note that the &#8220;gate&#8221; switch in &#8216;real&#8217; server&#8217;s parameter value which testifies the usage of LVS Direct Routing method. The rest of the two methods are masq and ipip the details of which along with the other options available, particularly the scheduler parameters, for this configuration file can be found in &#8216;man ldirectord&#8217;.</p>
<p><em><strong>Testing</strong></em></p>
<p><em><strong></strong></em>Use &#8216;ipvsadm&#8217; to list down current statistics of ldirectord. Make sure that both real servers IPs are listed there and have non-zero value in weight (since we&#8217;ve this default setup, it should be 1). If not, then try checking the log file, tcpdump on ldirector and apache logs on real servers.<br />
If everything works good, you&#8217;ll see changing content when browsing to http://10.10.10.60/ multiple times (from another system outside these cluster nodes). Then stop httpd on one web server, browse to the URL again and all requests should now be served from the other web server.</p>
<pre class="brush: bash;">
[root@VM1 ~]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-&gt; RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.10.10.60:http wrr
-&gt; 10.10.10.63:http             Route   1      0          0
-&gt; 10.10.10.62:http             Route   1      0          0
</pre>
<p>For a more meaningful testing</p>
<pre class="brush: bash;">
$ for i in $(seq 6); do curl http://10.10.10.60/index.html; done
 This is VM3
 This is VM2
 This is VM3
 This is VM2
 This is VM3
 This is VM2
</pre>
<p>I&#8217;ll be posting a couple of optimizations techniques soon when I&#8217;ll be getting some more free time. Stay tuned and take care <img src='http://bashukhan.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 1388px; width: 1px; height: 1px;">checktimeout=10<br />
checkinterval=2<br />
autoreload=no<br />
logfile=&#8221;/var/log/ldirectord.log&#8221;<br />
quiescent=yes<br />
virtual=10.10.10.60:80<br />
real=10.10.10.62:80 gate<br />
real= 10.10.10.63:80 gate<br />
service=http<br />
request=&#8221;index.html&#8221;<br />
receive=&#8221;hi&#8221;<br />
scheduler=wlc<br />
protocol=tcp<br />
checktype=negotiate</div>
]]></content:encoded>
			<wfw:commentRss>http://bashukhan.com/ha-lb-cluster-on-centos5-without-actual-heartbeat-p/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
