Setting up an Application Load Balancer with AWS EC2

Setting up an Application Load Balancer with AWS EC2

Day 41

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:

    1. Application Load Balancer (ALB) - operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices.
  1. Network Load Balancer (NLB) - operates at layer 4 of the OSI model and is ideal for applications that require high throughput and low latency.
  1. 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.

    1. Log into your AWS Console and go to the EC2 dashboard.

    2. Click on the "Launch Instance" button and select "Ubuntu Server ".

    3. Choose the instance type, configure the instance details, add storage, and configure security groups as required.

    4. In the "Configure Instance Details" page, scroll down to the "Advanced Details" section and expand the "User data" field.

    5. In the "User data" field, enter the following commands to install and start the Apache web server:

       #!/bin/bash
      
       apt-get update
       apt-get install -y apache2
       systemctl start apache-2
       systemctl enableapache-2
      

    6. In summary, give a number of Instance 2 and click on Lunch Instance.

    7. You can see two instances are created.

  • Copy the public IP address of your EC2 instances.

  • Open a web browser and paste the public IP address into the address bar.

  • You should see a webpage displaying information about your PHP installation.

    1. Apache Server 1.

    2. Apache Server 2.

  • Modify the index.html file to include your name so that when your Apache

    the server is hosted, it will display your name also do it for 2nd instance which includes " DevOps Community is Super Awesome :) ".

    1. Connect Instances using SSH.

    2. Go inside the/var/www/html path and edit the index.html file

Task 2:

LoadBalancer

  • Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.

  • Add EC2 instances that you launch in task-1 to the ALB as target groups.

  • Verify that the ALB is working properly by checking the health status of the target instances and testing the load-balancing capabilities.

    1. Log in to the AWS Management Console and go to the EC2 dashboard.

    2. Click on "Load Balancers" in the left-hand navigation menu and then click the "Create Load Balancer" button.

    3. Select "Application Load Balancer" as the load balancer type and click "Create".

    4. 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.

    5. Configure "Security Groups"

    6. Now in the Listeners and routing Section there, you find the select target group but we don't have the Target group So we click on Create Target Group and it will take you to a new browser. Now you have to Select Target Type as an Instance Because we use our ec2 instance for load balancing. If you want to set with ip select that. There are 4 Target types. Now enter the Target group name.

    7. Scroll Down to the bottom and click on Next. Now you see There is your all-running instance so you have to select instance for load balancing And click on Include as pending below

      Now you have the option to review targets review and click on Create Target Group

    8. Back go to the browsers Load Balancer tab and refresh the target group section and there you will find the target group that you created now select that.

    9. Scroll down and there you will see the summary about the load balancer review it and click on Create the load balancer.

    10. Now you Successfully Created a Load balancer for the EC2 instance. click on view load balancer and see the all things about your Load balancer.

    11. Now it Its Time to test your Load Balancer. Copy the DNS name from the Load balancer Description and paste it into a new browser tab.

Thankyou....