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:
1. Application Load Balancer (ALB) - operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices.
2. 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.
Task 1:
Launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.
Login to AWS Console and navigate to the EC2 service.
Click on "Launch Instances" and create 2 Ubuntu instances.
Choose Amazon Machine Image (AMI)" as Ubuntu Server 20.04 and t2micro
Select the instance type as t2micro and provide the keypair value
In the Network settings, Configure the storage section to provide your VPC and security groups or leave it to the default.
Under Advanced details > User data, write a script to install Apache server
#!/bin/bash sudo apt-get update sudo apt-get install -y apache2 sudo systemctl start apache2 sudo systemctl start apache2
Click on "Launch Instances" to launch the instance.
Two Ubuntu instances will be created
Now connect to the instances to check if the Apache webserver is running
sudo systemctl status apache2
Now we will edit the index.html file of Apache server
cd /var/www/html vi index.html <body> <p> Hi everyone this is Rajendra Apache pagde </p> </body>
Let's access the Apache webserver with Instance publicIP:80
In this way, we can install any application from user data while launching an instance.
Task 2:
Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.
Login to AWS console and navigate to load balancers > Create load balancer
Select the load balancer type as an Application load balancer
Configure the load balancer such as name, scheme, IP address type, listeners, security group, and availability zones. For the listener, you can choose HTTP or HTTPS, depending on your application's requirements.
Under Network mapping configure the VPC and mapping zones all
For listeners and routing we need to specify the target group, since we don't have any we need to create one here. So click on Create target group and the target type will be the instance.
Provide the name of the target group and click on Next
You will be able to see the running instances, here select an instance for which you wanted to register targets as LB.
Now click on create target group
To fix the Access issue detected apply all the 3 zones in subnet
Now get back to Listeners and routing and apply the target group
Click on Create Load balancer
Now test your Load Balancer. Copy the DNS name from Load balancer Description and paste in a new browser tab.