๐ Introduction:
In this blog, we will we are going to deep dive into one of the most important concepts in AWS, Load Balancing.
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.
Task: 1
launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.
Log in to our AWS Console and go to the EC2 dashboard.
Click on the Launch Instance button and select Ubuntu AMI.
- In the User data field, enter the following commands to install start & enable the Apache web server
#!/bin/bash
sudo apt-get update -y
#Install Apache2
sudo apt-get install -y apache2
#Start Apache2 service
sudo systemctl start apache2
#Enable Apache2 to start on boot
sudo systemctl enable apache2
- 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 :) ".
- For apache-server1 Check apache2 status
- Go inside /var/www/html path and edit the index.html file
- To check on the web browser copy and paste the public IP address.
- For apache-server2 Check apache2 status
- Go inside /var/www/html path and edit the index.html file
- To check on the web browser copy and paste the public IP address.
Task: 2
Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.
Log in to the AWS Management Console and go to the EC2 dashboard.
Click on Load Balancers in the left-hand navigation menu and then click the Create Load Balancer button.
- Select Create Load Balancer then click on Application Load Balancer
- Configure the load balancer settings, such as name, listener, security group, and availability zones. For the listener, you can choose HTTP or HTTPS, depending on your application's requirements
- Create & Configure Security Groups
- Create a target group by specifying a name, protocol, port, and health check settings. Choose the same availability zones as the load balancer and select the instances that you launched in Task 1 as targets for the target group.
Add EC2 instances which you launch in task-1 to the ALB as target groups
Select both the instance & click on Include as pending below
- Review targets & click on Register pending targets
- Target group is created
- Load balancer is created
- Test the load balancing capabilities by accessing the load balancer's DNS name in a web browser. You should see traffic being evenly distributed across the instances.
๐ Conclusion :
In this blog, we have covered what load balancing is and how to use Elastic Load Balancing (ELB) in AWS EC2, a service that automatically distributes incoming traffic across multiple EC2 instances., in the next blog we will cover AWS Advanced Topics.
Thank you for reading!
Contact me on Linkedin
Check out my GitHub for more resources ๐