<?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>dKaiser &#187; Amazon ELB</title>
	<atom:link href="http://www.dkaiser.com/blog/tag/amazon-elb/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dkaiser.com/blog</link>
	<description>- Experiments with Clouds</description>
	<lastBuildDate>Mon, 30 Jan 2012 20:23:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Amazon AWS Elastic Load Balancing</title>
		<link>http://www.dkaiser.com/blog/amazon-aws-elastic-load-balancing?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=amazon-aws-elastic-load-balancing</link>
		<comments>http://www.dkaiser.com/blog/amazon-aws-elastic-load-balancing#comments</comments>
		<pubDate>Sun, 22 Nov 2009 17:04:05 +0000</pubDate>
		<dc:creator>Pauli Haikonen</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Amazon ELB]]></category>
		<category><![CDATA[availability]]></category>

		<guid isPermaLink="false">http://www.dkaiser.com/blog/?p=87</guid>
		<description><![CDATA[TweetAmazon ELB was announced in May and is currently in public beta phase. Previously, HAproxy was the way to go if a customer wanted load balancing within EC2 environment. Amazon ELB is an automatic load balancing solution which detects AWS instance health and distributes traffic accordingly, even across availability zones, but not across regions. The [...]]]></description>
			<content:encoded><![CDATA[<div class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.dkaiser.com%2Fblog%2Famazon-aws-elastic-load-balancing&amp;text=Amazon%20AWS%20Elastic%20Load%20Balancing&amp;related=&amp;lang=en&amp;count=&amp;counturl=http%3A%2F%2Fwww.dkaiser.com%2Fblog%2Famazon-aws-elastic-load-balancing" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.dkaiser.com/blog/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Amazon ELB was <a href="http://aws.amazon.com/about-aws/whats-new/2009/05/17/monitoring-auto-scaling-elastic-load-balancing/">announced</a> in May and is currently in public beta phase. Previously, HAproxy was the way to go if a customer wanted load balancing within EC2 environment. Amazon ELB is an automatic load balancing solution which detects AWS instance health and distributes traffic accordingly, even across availability zones, but not across regions. The costs of using the service are really not that high, $0.025 per hour and $0.008 per GB transferred.</p>
<p>I wanted to test the ELB service with my simple WordPress installation. I have all the service in one Amazon AWS instance, since, well&#8230; I don&#8217;t have any sponsors to help with the testing. Thus, I had to setup another instance for the test. Of course, I was then running a duplicate database server as well, but for testing purposes this is all fine. I wanted to test the ELB across availability zones, so I started the instance in eu-west-1a while I had the old instance in eu-west-1b.</p>
<p><strong>Tools:</strong></p>
<p>To get started with Amazon Elastic Load Balancing, <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2536&amp;categoryID=88">ELB API tools</a> must be installed. The tools are installed on your own computer, so you must somehow tell Amazon who you are. There are two ways of describing this to EC2. The tools come with desription in the readme.txt of how to use either one of them. I decided to use the one where each command is appended with descriptions of where the credentials are. You can test the ELB service and your credentials by first querying the currently created load balancers with a command:</p>
<p><em>C:\Program Files\Support Tools&gt;%AWS_ELB_HOME%\bin\elb-describe-lbs &#8211;headers &#8211;ec2-cert-filepath=E:\backup_amazon_certs\cert.pem &#8211;ec2-private-key-file-path=E:\backup_amazon_certs\pk.pem</em></p>
<p>The command should return &#8220;No LoadBalancers found&#8221; if you have not created any and if the command successfully completes.</p>
<p><strong>Installing ELB:</strong></p>
<p>First thing to do is to create a load balancer. The command is:</p>
<p><em>C:\&gt;%AWS_ELB_HOME%\bin\elb-create-lb wpLoadBalancer &#8211;headers &#8211;listener &#8220;lb-port=80,instance port=80,protocol=HTTP&#8221; &#8211;availability-zones eu-west-1a &#8211;region eu-west-1 &#8211;ec2-cert-file path=E:\backup_amazon_certs\cert.pem &#8211;ec2-private-key-file-path=E:\backup_amazon_certs\pk.pem</em></p>
<p>In the above command, I create a load balancer with a name wpLoadBalancer and isntruct the balancer to listen port 80 to incoming requests and also connecting to port 80 in my instances which are to be load balanced. I set the availability zone to be eu-west-1a and the region to be eu-west-1 and the rest is to give information to EC2 of who I am. EC2 will respond with a public DNS name, for example wpLoadBalancer-26728261.eu-west-1.elb.amazonaws.com which doesn&#8217;t look too nice, but not to worry, the idea is to create a CNAME record using this information. Of course, this is problematic as you can&#8217;t put a CNAME record to the root of the domain.</p>
<p>Next step is to create the health check which the load balancer will use in deciding if the instance is available of not. This is really easy if you know what to do! The load balancer will make make a HTTP GET to the web server for a particular file. If the file is available, the status is OK and the instance is added in the pool of servers. The command is:</p>
<p><em>C:\&gt;%AWS_ELB_HOME%\bin\elb-configure-healthcheck wpLoadBalancer &#8211;headers &#8211;region eu-west-1 &#8211;target &#8220;HTTP:80/ping&#8221; &#8211;interval 30 &#8211;timeout 3 &#8211;unhealthy-threshold 2 &#8211;healthy-threshold 2 &#8211;ec2-cert-file-path=E:\backup_amazon_certs\cert.pem &#8211;ec2-private-key-file-path=E:\backup_amazon_certs\pk.pem</em></p>
<p>EC2 will answer with an ack:<br />
<em>HEALTH-CHECK TARGET INTERVAL TIMEOUT HEALTHY-THRESHOLD UNHEALTHY-THRESHOLD<br />
HEALTH-CHECK HTTP:80/ping 30 3 2 2</em></p>
<p>This means that the ELB will try to get a file called &#8220;ping&#8221; from the root of the web server every 30 seconds. The timeout for each request is three seconds and if two pings are missing, the server is removed from the pool until two successful pings are received. I had no previous experience with this, so it took a while to figure out how the ping actually works, but actually all you need is an empty file with that name (or what ever you define in the health check). Important thing is to really keep that empty, because that is just unnecessary traffic if the file would have a size. If the file can&#8217;t be found, Apache will respond with a 404 code, while the load balancer wants a 200 code.</p>
<p>Instances are added in the load balancer with the following command:</p>
<p><em>C:\&gt;%AWS_ELB_HOME%\bin\elb-register-instances-with-lb wpLoadBalancer &#8211;headers &#8211;region eu-west-1 &#8211;instances i-55555555,i-44444444 &#8211;ec2-cert-file-path=E:\backup_amazon_certs\cert.pem &#8211;ec2-private-key-file-path=E:\backup_amazon_certs\pk.pem</em></p>
<p>And EC2 responds with:</p>
<p><em>INSTANCE-ID INSTANCE-ID<br />
INSTANCE-ID i-55555555<br />
INSTANCE-ID i-44444444</em></p>
<p>One thing to notice here is that you can add instances in the load balancer which are not in the availability zone where the load balancer is. I made a mistake here and were wondering why my other instance&#8217;s access log was not getting any hits from the load balancer. The command</p>
<p><em>C:\&gt;%AWS_ELB_HOME%\bin\elb-describe-instance-health wpLoadBalancer &#8211;headers &#8211;region eu-west-1 &#8211;ec2-cert-file-path=E:\backup_amazon_certs\cert.pem &#8211;ec2-private-key-file-path=E:\backup_amazon_certs\pk.pem</em></p>
<p>And gave a response:</p>
<p><em>INSTANCE-ID INSTANCE-ID STATE<br />
INSTANCE-ID i-55555555 OutOfService<br />
INSTANCE-ID i-44444444 InService</em></p>
<p>The problem was fixed by extending the load balancer to cover the eu-west-1b availability zone. How cool is that! Just one command and the balancer covers a new zone! The command was:</p>
<p><em>C:\&gt;%AWS_ELB_HOME%\bin\elb-enable-zones-for-lb wpLoadBalancer &#8211;availability-zones eu-west-1b &#8211;headers &#8211;region eu-west-1 &#8211;ec2-cert-file-path=E:\backup_amazon_certs\cert.pem &#8211;ec2-private-key-filepath=E:\backup_amazon_certs\pk.pem</em></p>
<p>And finally, I had both of my instances with InService state. I could now start the actual balancing of requests for two different sites. I did not do any proper load test by generating load on the instances, I just wanted to test the availability by stopping Apache on either one of the intances. I also edited the www.dkaiser.com CNAME record which was previously pointing to dkaiser.com HOST A record (with elastic IP) and now to the public DNS name of the load balancer.</p>
<p>The first tests were unsuccesful. All was fine when the Apache was running on the instance which had the public Elastic IP configured, suggesting the load balancer did not really distribute traffic to the other node when the first one failed. It just did not work, though the instance was in &#8220;InService&#8221; state. I then started to google a bit and it became apparent, that the ELB uses a kind of fancy round-robin in distributing requests to a zone. More details <a href="http://developer.amazonwebservices.com/connect/message.jspa?messageID=135534">here</a>. The point is, there should always be a properly functioning instance per availability zone. This means, having one instance per zone doesn&#8217;t really cut it. After I realized my mistake, I had to disable one of the zones from the load balancer, terminate the instance, boot a new instance in eu-west-1b attach volumes and add the new instance to the wpLoadBalancer (once again, how cool is that!). I could now shut down either one of the Apache processes and the site would be up. All as expected.</p>
<p><strong>Summary:</strong></p>
<p>Amazon ELB seems like a great way to load balance traffic. It is also quite cheap. One draw back is the fact that you have to make a CNAME record for the load balancer. This makes it impossible to load balance traffic directed to the root of the site. Fixing this issue is on Amazon&#8217;s tasks of future improvements.</p>
<p>Pauli Haikonen</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dkaiser.com/blog/amazon-aws-elastic-load-balancing/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

