Setting up an Application Load Balancer with AWS EC2 🚀
This is Day 41 of #90daysofdevops challenge
Hi, I hope you had a great day yesterday learning about the launch template and instances in EC2. Today, we are going to dive into one of the most important concepts in EC2: 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.
What is Elastic Load Balancing ?
Elastic Load Balancing distributes incoming application traffic across multiple Amazon EC2 instances. It enables you to achieve fault tolerance, scalability and high availability for your applications.
Types of load balancers:
Classic Load Balancer - Operates at the transport layer (Layer 4). Supports HTTP and HTTPS listeners.
Application Load Balancer - Operates at the application layer (Layer 7). Supports HTTP/HTTPS and WebSockets.
Network Load Balancer - Operates at the transport layer and is optimized for high performance.
In summary, Elastic Load Balancing enables you to distribute traffic across multiple EC2 instances. It provides benefits like fault tolerance, scalability, high availability and security. The different load balancer types give you options based on your performance and functionality requirements.
Task 1: AWS EC2 Apache Server Setup with Custom Web Pages
- Launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.
Launch EC2 Instances:
Log in to your AWS Management Console.
Navigate to the EC2 service.
Click "Launch Instance."
Choose an Ubuntu AMI from the available options.
Select the instance type and configure other settings as needed.
In the "User Data" field, you can add a script to install Apache.
Here's a sample User Data script:
#!/bin/bash
apt update -y
apt install apache2 -y
systemctl start apache2
systemctl enable apache2
- Connect your ec2 instance.
Use the command below to check the status of Apache 2:
sudo systemctl status apache2
Modify the index.html file to include your name so that when your Apache server is hosted, it will display your name.
Go inside /var/www/html/ path and edit index.html file
- Add html code below <title> tag to show your name.
Copy the public IP address and paste it into the address bar of a web browser.
A webpage with details about your PHP installation ought to appear.
Task 2: Setting Up AWS Application Load Balancer (ALB) and Target Groups for EC2 Instances
- Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.
Create Target Groups:
In the EC2 dashboard, under "Load Balancing," click on "Target Groups."
Click the "Create target group" button.
Configure the target group settings, including the protocol (HTTP), port (80), and the health check settings.
You have to register targets instances to target group.
Select the instances which you wanted to add.
Click on “Include as pending below”.
Hit on the “Create target group”.
- Now go back to your "Load Balancer" tab and click on the refresh button near the "Default action" and then you will see the new target group we just created.
Create an Application Load Balancer (ALB):
Log in to your AWS Management Console.
Navigate to the EC2 service.
In the left sidebar, under "Load Balancing," click on "Load Balancers."
Click the "Create Load Balancer" button.
Choose "Application Load Balancer" and click "Create."
Configure the ALB settings, including the VPC, availability zones, and listeners. Make sure to select HTTP (port 80) as a listener.
Set up security groups and configure routing as needed.
- Choose at least 2 subnet.
- In the listener, section attaches the target group that you have created previously.
Verify that the ALB is working properly by checking the health status of the target instances and testing the load balancing capabilities.
We’ll check the health status of the Target Group.
- Now let's check the status of Load balancer.
Load balancer is successfully created in Active state.
You can now copy the DNS of your load balancer and paste it into your browser to see different webpages
"Thank you for enjoying my DevOps blog! Your positive response fuels my passion to dive deeper into technology and innovation.
Stay tuned for more captivating DevOps articles, where we'll explore this dynamic field together. Follow me on Hashnode and connect on LinkedIn (https://www.linkedin.com/in/som-shanker-pandey/) for the latest updates and discussions.