Elastic Load Balancing ( ELB ) is an AWS load balancer service that is readily available for users who have signed up for AWS EC2 and s3 services . ELB is configured to automatically distribute incoming application traffic across multiple Amazon EC2 instances . Recently AWS has announced support for ELB to the AWS Management Console which will give users a simple, point-and-click web interface to create and configure load balancers for the AWS EC2 instances .
Below are the simple steps to configure ELB for webserver from the command line .
1 ) Setting up the tools
Download the ELB API Tool and set the environmental variables
[bash]export JAVA_HOME=/path/to/java
export EC2_PRIVATE_KEY=/path/to/key
export EC2_CERT=/path/to/cert
export AWS_ELB_HOME=/path/to/ELB-API-TOOLS
export PATH=$PATH:$AWS_ELB_HOME/bin[/bash]
2 ) Create an HTTP Load Balancer
[bash]elb-create-lb LoadBalancerName –headers –listener “lb-port=80,
instance-port=80,protocol=http” –availability-zones us-east-1a[/bash]
3 ) Register Instances with ELB
[bash]elb-register-instances-with-lb LoadBalancerName –headers –instances
i-11111111,i-22222222[/bash]
4 ) Configure DNS
since ELB does not work on the root of a domain , you have to redirect it to www and set CNAME for www as the ELB DNS name . So set domain forwarding for root domain to www and set CNAME for www in the DNS management portal .
[bash]
TYPE CNAME
TTL 5
NAME WWW
VALUE DNS-NAME-OF-ELB
[/bash]
5 ) Configure Health Check
check the health of the instances registered with ELB .
i)Configure a TCP healthcheck with target port 8080
[bash]elb-configure-healthcheck LoadBalancerName –headers
–target “TCP:8080″ –interval 5 –timeout 3 –unhealthy-threshold 2
–healthy-threshold 2[/bash]
ii) Configure an HTTP healthcheck with target port 80 with a path
[bash]elb-configure-healthcheck LoadBalancerName –headers
–target “HTTP:80/status” –interval 5 –timeout 3
–unhealthy-threshold 2 –healthy-threshold 2[/bash]
6 ) check the ELB and instance Health
i ) Describe the state of all instances for LoadBalancer “LoadBalancerName”
[bash]elb-describe-instance-health LoadBalancerName –headers[/bash]
ii ) Describe the state of specific instances for LoadBalancer
[bash] elb-describe-instance-health LoadBalancerName –headers
–instances i-11111111 , i-22222222 [/bash]
7 ) Deregistering instances from ELB
[bash]elb-deregister-instances-from-lb LoadBalancerName –headers
–instances i-11111111,i-22222222 [/bash]
8 ) Expand a Load Balanced Application to an Additional Availability Zone
Suppose that you have 2 ec2 instances ( i-11111111 and i-22222222 ) running in the availability zone us-east-1a is registered with an ELB . You want to register 2 more ec2 instances ( i-33333333 and i-44444444 ) present in the availability zone us-east-1b with the same ELB .
i ) Register the new instances ( i-33333333 and i-44444444 ) that are in the new zone ( us-east-1b ) with the load balancer
[bash] elb-register-instances-with-lb LoadBalancerName –headers
–instances i-33333333 , i-44444444 [/bash]
ii ) Enable the new zone for the Load Balancer.
[bash]elb-enable-zones-for-lb LoadBalancerName –headers
–availability-zones us-east-1b [/bash]
9 ) Disable an Availability Zone from a Load Balanced Application
[bash]elb-disable-zones-for-lb LoadBalancerName –headers
–availability-zones us-east-1a [/bash]
[bash]elb-deregister-instances-from-lb MyLoadBalancer –headers
–instances i-11111111 , i-22222222[/bash]
10 ) Tear Down an Existing LoadBalancer
[bash] elb-delete-lb MyLoadBalancer [/bash]
[…] article explains how to deploy an e-commerce application that is load balanced using ELB ( Elastic Load Balancer ) in AWS EC2. This article is based on our experience in deploying […]