Elastic Load Balancer (ELB)

Mansi Dadheech
4 min readAug 9, 2020

Load Balancing is the methodology to manage distributed server and client traffic in an efficient manner.
We can understand it with an example like:
Suppose we have launch an instance on AWS in a particular availability zone having a configured apache webserver on it.
If a client wants to connect with webserver, he have to send IP and Port.There might be possibility that this OS can’t accommodate 1000s of clients and due to this client won’t get proper connectivity.
Or there may be chances that due to any disaster or natural calamity that availability zone goes down and due to this clients face issue in connectivity.

So to resolve thes issue we can launch same server/instance in multiple availability zone.
Merits of launching same server in multiple AZ’s:
1. Disaster Recovery.
2. Load balancing.

ELB i.e. Elastic Load Balancer is the AWS service which maintains,setup and configure load balancer by managing sessions of requests made by client and sends these request to the server/ec2 instances.
As its name claims ‘elastic’ means — as requirement comes up it will increase or decrease the resources.
ELB is same like Service on Kubernetes.

ELB supports three types of load balancer:
1. Classic Load Balancer
2. Application Load Balancer
3. Network Load Balancer

Creating an ELB:

To create a load balancer, first we need to launch instances and configure web server on that.

  1. Launching an Instance: Using Amazon Linux V-2 image:

While configuring instance details- choose a subnet and disable public Ip because when two programs running inside same VPC they don’t require public IP, they can connect with private also.

Cloud-Init: Almost all cloud images contain a program which run at a time of booting that program is known as cloud Init.
This program has the capability to go behind the managed services which are consist of metadata to check whether a user given a command or script or not to run or download at the time of booting.

We can do this while launching instance while configuring instance details by User Data feature:

#!/bin/bash
yum update -y
yum install httpd php -y
systemctl start httpd.service
systemctl enable httpd.service
echo “hiii $(hostname -f)” > /var/www/html/index.html
echo '<pre> <?php print(`ifconfig`); ?> </pre>' > /var/www/html/myip.php

As we have to configure apache web server, so we can do this while launching also. Now in security group we can allow only HTTP protocol and proceed without a key pair.

After launching an instance we can check our server by associating a Elastic IP.

Now we can launch one more instance like this,and only change subnet and tag.

2. Creating a Load Balancer:

Choosing Classic Load Balancer.

Step-1: Define Load Balancer: Here we just need to give name and select VPC.

Step-2: Assign Security Group: Creating a new security group. Choosing Custom TCP type as http uses port 80 by default.

Step-3: Configure Security Settings:

Step-4: Configuring Health Check: As load balancer keep on checking backend servers about health check i.e. live or dead.

Step-5: Add Instances: Adding instances means registering these instances for load balancing.

Now our load balancer is created with our two registered instances .

3. Testing our load balancer.

By writing url of load balancer we can access our server:

Here it is showing IP of server-1.
To check our load balancer I have stopped my first instance:

We can see server1 is out of service.

Now on browser it is showing IP pf second server:

Thanks for reading and thanks to vimal sir!!

--

--

Mansi Dadheech

Exploring various disciplines to broaden my own pursuits✨.