Tech Junkie Blog - Real World Tutorials, Happy Coding!: Iaas With AWS: Create A Classic Load Balancer

Monday, November 16, 2020

Iaas With AWS: Create A Classic Load Balancer

 In the previous post we went over what a load balancer is, in this post we are going to create one of types of load balancer AWS offers.  We are going to create a Classic Load Balancer, this balancer is not recommended by Amazon, you should only create this if you have to support EC2-Classic instances.

Before we create the load balancer we need to create more than one instances with a web server because we need to test that the load balancer is able to switch.

1. Create two instances with the user data to create Apache Web Servers with these commands in the User Data for instance, if you need the full instruction on how to create instances with User Data you can read this post

#cloud-boothook
#!/bin/bash
#Use this for your user data (script without newlines)
# install httpd (Linux 2 version)

yum update -y 
yum install -y httpd.x86_64 
systemctl start httpd.service 
systemctl enable httpd.service 
echo "Hello world from $(hostname -f)" > /var/www/html/index.html

We just created an index.html file to write out the hostname for testing later on


2. For the Security Groups setting make sure there's an inbound rule for HTTP traffic



3. On the create the two instances, if you copy and paste the public DNS or public IP into the address bar of the browser you see the hostname being printed out for the instance, so if the load balancer is successfully the request should change to a different host when a user requests the site
Now its time to create the Classic Load Balancer

4. On EC2 Dashboard scroll down to "LOAD BALANCING" and click on "Load Balancers",  then click on the "Create Load Balancer" button you will be presented with three choices.  The Classic Load Balancer is grayed out because AWS does not want you to choose it.  Choose the Classic Load Balancer by clicking on the "Create" button

5.  On the next page accept the default because Load Balancer accepts HTTP requests on port 80, so does our instance

6. On the Security Groups page, make sure that you have an inbound rule that accepts HTTP requests on port 80


7.  The next page is the Health Check page, it will check the health of the instances by pinging the page index.html on port 80, accept the default and click Next

8.  On Add EC2 Instances page you want to add the two instances that we've created with the User Data and accept the default, then click "Next" , click on "Review and Create" and then click on "Create"
Once the Load Balancer has been created you can copy and paste the Load Balancer's DNS into the browser's address bar and it would alternate between the two instances.  You will have to wait for a while for it to work, the instances will have a status of OutOfService while it is being added to the load balancer


Here is result you should get when everything is finished.


1 comment:

Search This Blog