Day 41: Setting up an Application Load Balancer with AWS EC2 ๐ โ
What is Load Balancing?
Load balancing is the distribution of workloads across multiple servers to ensure consistent and optimal resource utilization. It is an essential aspect of any large-scale and scalable computing system, as it helps you to improve the reliability and performance of your applications.
Elastic Load Balancing:
Elastic Load Balancing (ELB) is a service provided by Amazon Web Services (AWS) that automatically distributes incoming traffic across multiple EC2 instances. ELB provides three types of load balancers:
Application Load Balancer (ALB) - operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices.
Network Load Balancer (NLB) - operates at layer 4 of the OSI model and is ideal for applications that require high throughput and low latency.
Classic Load Balancer (CLB) - operates at layer 4 of the OSI model and is ideal for applications that require basic load balancing features.
๐ฏ Today's Tasks:
Task 1:
- launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server
Log in to your AWS Console and go to the EC2 dashboard.
Click on the "Launch Instance" button and select "Ubuntu Server ".
In the "Configure Instance Details" page, scroll down to the "Advanced Details" section and expand the "User data" field.
In the "User data" field, enter the following commands to install and start the Apache web server:
add below data
#!/bin/bash
sudo apt update
sudo apt install -y apache2
sudo systemctl start apache2
sudo systemctl enable apache2
You can see two instances are created
Modify the index.html file to include your name so that when your Apache server is hosted, it will display your name Also do it for 2nd instance which includes " TrainWithShubham Community is Super Awesome :) ".
Go inside /var/www/html path and edit the index.html file
Change the index.html
file in /var/www/html
directory
Now check the Public IP of instance 1 and you will see the HTML is running on the IP address.
Apache Server 2 Instance:
Change the index.html
file in /var/www/html
directory
Now check the Public IP of instance 1 and you will see the HTML is running on the IP address.
Task 2:
Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.
Open EC2 Dashboard
and click on Create Target Groups
the button.
Let's first specify the group details. Name the target group ApacheGroup
and select Instance
the target type. Click on Next
the button.
Now click on Load Balancers
and click on Create Application Load Balancer
button here we will add all the instances in the load balancer via Target Group
.
Name the Load Balancer ApacheLB
and select Internet-facing
the scheme. Click on Next
the button.
Select the VPC Default VPC
and select all the subnets. Next
we will redirect the traffic to the target group.
Let's check the Register Target to verify the instances are added in the load balancer.
Happy Learning!