DEV Community

Cover image for AWS Elastic Load Balancer
Kannan
Kannan

Posted on

AWS Elastic Load Balancer

We are going to see how to create a Elastic Load Balancer(ELB)

Step 1. we need to create and launch the instance with Ubuntu OS and with instance type as t2.nano and selected the existing key pair and security group and set 2 instance to create and launch.

Image description

Step 2. Edit the name as app_server-1 and app_server-2 for identification.
login via ssh using the public IP of each instance and do the "sudo apt update","sudo spt install apache2 -y" remove the index.html file and create and edit new index.html file.
Enable & verify the status of the service using "sudo systemctl enable apache2", "sudo systemctl status apache2".
verify the apache application by running "curl @(pubilc IP of EC2-Instance)"

kannan@kannan-PC:~$ ssh -i apache.pem ubuntu@13.234.122.186

ubuntu@ip-172-31-35-171:~$ sudo apt update

ubuntu@ip-172-31-35-171:~$ sudo apt install apache2 -y

ubuntu@ip-172-31-35-171:~$ sudo rm /var/www/html/index.html 
ubuntu@ip-172-31-35-171:~$ sudo vi /var/www/html/index.html 

ubuntu@ip-172-31-35-171:~$ sudo systemctl enable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2
ubuntu@ip-172-31-35-171:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-11-27 13:37:55 UTC; 1min 37s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 2249 (apache2)
      Tasks: 55 (limit: 517)
     Memory: 6.4M
        CPU: 39ms
     CGroup: /system.slice/apache2.service
             ├─2249 /usr/sbin/apache2 -k start
             ├─2251 /usr/sbin/apache2 -k start
             └─2252 /usr/sbin/apache2 -k start

Nov 27 13:37:55 ip-172-31-35-171 systemd[1]: Starting The Apache HTTP Server...
Nov 27 13:37:55 ip-172-31-35-171 systemd[1]: Started The Apache HTTP Server.

ubuntu@ip-172-31-35-171:~$ curl @13.234.122.186
<h1>Application running on server-1</h2>


Enter fullscreen mode Exit fullscreen mode

Step 3.Follow the above same procedure for the second instance and verify.

ubuntu@ip-172-31-34-163:~$ sudo rm /var/www/html/index.html 
ubuntu@ip-172-31-34-163:~$ sudo vi /var/www/html/index.html 
ubuntu@ip-172-31-34-163:~$ curl @13.109.139.153
<h1>Application running on server-2</h1>

Enter fullscreen mode Exit fullscreen mode

Now 2 apache application is running on the two instance.

Step 4. Create a Target group

Image description

Step 5. Create a Load Balancer

Image description

Step 6.Select and create Application load balancer type.

Image description

Step 7.Set the basic configuration

Image description

Step 8. Set Network mapping

Image description

Step 9. Set security group and select the target groups which we have created.

Image description

Step 10. On the summary tab we need to verify the settings and create the load balancer. it took approx 5 mins for provisioning.

Image description

Image description

Step 11. Once the ELB has been active open and copy the DNS and verify on the browser for every refresh it will change the instance using ELB.

Image description

Image description

Image description

Top comments (0)