A load balancer takes requests from clients and distributes them across targets in a target group.
Types of Elastic Load Balancers:
ELB supports three types of load balancers. We can select the appropriate load balancer based on our application needs.Network Load Balancer (NLB):
AWS Network Load Balancer (NLB) is an Amazon Web Services (AWS) tool that distributes end-user traffic across multiple cloud resources to ensure low latency and high throughput for applications. Network Load Balancer performs health checks on targets, which can be an EC2 instance, IP address, microservice or container. When a target becomes slow or unavailable, the Network Load Balancer routes traffic to another target. If the service does not detect any healthy targets within a given Availability Zone (AZ), it can fail over to resources in another AZ. If the Network Load Balancer itself becomes unresponsive, integration with Amazon Route 53 can direct traffic to an alternate load balancer in another region.
Steps we need to follow:
1. Create a Linux Web Server which should work on port 802. Create a Windows Web Server which should work on port 8080
3. Create an index.html file in the document root of the IIS Server
4. Inside IIS, update port from 80 to 8080
5. Open Port 8080 in Firewall of Windows instance
6. Configure Target Groups for Linux and Windows instances
7. Register EC2 instances to each Target Group
8. Allocate two Elastic IPs
9. Create a Network Load Balancer (NLB)
10. Update Listeners in Load Balancer
11. Access website through DNS name
Step 1: Create a Linux Web Server which should work on port 80:
AWS ➔ Services ➔ EC2 ➔ Instances ➔ Launch Instance ➔ [*] Free Tier Only ➔ Select any Linux AMI ➔ Select ➔ Instance Type: 't2.micro' ➔ Configure Instance: Number of Instances: 1 ➔ Select VPC ➔ Select Public Subnet (I'm selecting us-east-1a) ➔ Auto-assign Public IP: should be Enable ➔ Advanced Details ➔ User Data: As text ➔ provide a script:
yum install -y httpd
echo "*** This is Linux WebServer ***" >> /var/www/html/index.html
systemctl --now enable httpd
Next: Storage ➔ Next Tags: 'Click to add a Name Tag' ➔ Key: Name & Value: Linux-Web-Server ➔ Next: Security Group ➔ Assign a security group: (*) Create a new security group OR ( ) Select an existing security group (but port for SSH (22) and HTTP (80) should be enabled ➔ Review and Launch ➔ Launch ➔ Create or provide an existing key-pair➔ Launch Instances.
*** This is Linux WebServer ***
Step 2: Create a Windows Web Server which should work on port 8080:
(1) Create a Windows instance:
AWS ➔ Services ➔ EC2 ➔ Instances ➔ Launch Instance ➔ [*] Free Tier Only ➔ Select Windows 2008 Server AMI ➔ Select ➔ Instance Type: 't2.micro' ➔ Configure Instance: Number of Instances: 1 ➔ Select VPC ➔ Select Public Subnet (I'm selecting us-east-1a) ➔ Auto-assign Public IP: should be Enable ➔ Next: Storage ➔ Next Tags: 'Click to add a Name Tag' ➔ Key: Name & Value: Windows-Web-Server ➔ Next: Security Group ➔ Assign a security group: Create a new security group OR Select an existing security group, but port for RDP (3389) and Custom (8080) should be enabled ➔ Review and Launch ➔ Launch ➔ Create or provide an existing key-pair➔ Launch Instances.
(2) Create an IIS Web Server in this Windows instance:
Login to AWS Windows EC2 instance ➔ Start ➔ Administrative Tools ➔ Server Manager ➔ Roles ➔ Add Roles ➔ Next ➔ [*] Web Server (IIS) ➔ Next ➔ Next ➔ Install ➔ Close.
AWS ➔ Services ➔ EC2 ➔ Instances ➔ Launch Instance ➔ [*] Free Tier Only ➔ Select Windows 2008 Server AMI ➔ Select ➔ Instance Type: 't2.micro' ➔ Configure Instance: Number of Instances: 1 ➔ Select VPC ➔ Select Public Subnet (I'm selecting us-east-1a) ➔ Auto-assign Public IP: should be Enable ➔ Next: Storage ➔ Next Tags: 'Click to add a Name Tag' ➔ Key: Name & Value: Windows-Web-Server ➔ Next: Security Group ➔ Assign a security group: Create a new security group OR Select an existing security group, but port for RDP (3389) and Custom (8080) should be enabled ➔ Review and Launch ➔ Launch ➔ Create or provide an existing key-pair➔ Launch Instances.
(2) Create an IIS Web Server in this Windows instance:
Login to AWS Windows EC2 instance ➔ Start ➔ Administrative Tools ➔ Server Manager ➔ Roles ➔ Add Roles ➔ Next ➔ [*] Web Server (IIS) ➔ Next ➔ Next ➔ Install ➔ Close.
Fig: IIS Web Server |
Step 3: Create an index.html file in the document root of the IIS Server:
Make an RDP connection with Windows Web Server ➔ Navigate to C:\inetpub\wwwroot ➔ Create index.html file with matter:*** This is Windows Web Server ***
Step 4: Inside IIS, update port from 80 to 8080:
Navigate to Windows server RDP connection ➔ click on Start ➔ Administrative Tools ➔ Internet Information Services (IIS) Manager ➔ expand the machine ➔ expand Sites ➔ click on Default web site ➔ click on 'Bindings' in Actions in the right side of this window…
Fig: Internet Information Services (IIS) Manager |
…click on default port 80 ➔ Edit ➔ update port from 80 to 8080 ➔ Ok.
Fig: Edit Site Binding |
Step 5: Open Port 8080 in Firewall of Windows instance:
Navigate to Windows server RDP connection ➔ click on start ➔ Administrative Tools ➔ Windows Firewall with Advanced Security ➔ Inbound Rules ➔ click on New Rule in the right side of Actions ➔ Rule Type: Port ➔ Next ➔ Specific local ports: 8080 ➔ Next ➔ [*] Allow the connections ➔ Next ➔ click on all 'Domain', 'Private' and 'Public' ➔ Next ➔ Name: port8080 (you can give any name) ➔ Finish.
So, now we have an incoming rule in the list.
Step 6: Configure Target Groups for Linux and Windows instances:
As we have two Web Servers, we need to configure two Target Groups. First, configure Target Group for Windows:
AWS ➔ Services ➔ EC2 ➔ Target Groups ➔ Create Target Group ➔ Target Group Name: windows-tg ➔ Target type: Instance ➔ Protocol: TCP ➔ Port: 8080 ➔ VPC: webshack-vpc ➔ Health Check Settings ➔ Protocol: HTTP ➔ Path: / ➔ Advanced health check settings can use default ➔ Create ➔ Close.
Now, configure Target Group for Linux:
AWS ➔ Services ➔ EC2 ➔ Target Groups ➔ Create Target Group ➔ Target Group Name: linux-tg ➔ Target type: Instance ➔ Protocol: TCP ➔ Port: 80 ➔ VPC: webshack-vpc ➔ Health Check Settings ➔ Protocol: HTTP ➔ Path: / ➔ Advanced health check settings can be use default ➔ Create ➔ Close.
Step 7: Register EC2 instances to each Target Group:
For Linux Target Group:Click on linux-tg Target Group ➔ Targets ➔ Edit ➔ select Linux-Web-Server ➔ Add to registered ➔ Save.
For Windows Target Group:
Click on windows-tg Target Group ➔ Targets ➔ Edit ➔ select Windows-Web-Server ➔ Add to registered ➔ Save.
But the status of both of these Target Groups is 'unused' because no load balancer is being configured yet.
Step 8: Allocate two Elastic IPs:
Allocate two Elastic IPs from Amazon Pool (or you can use if you have your own):AWS ➔ Services ➔ EC2 ➔ Elastic IPs ➔ Allocate New Address ➔ IPv4 address pool: [*] Amazon pool ➔ Allocate ➔ Close.
Allocate one more:
AWS ➔ Services ➔ EC2 ➔ Elastic IPs ➔ Allocate New Address ➔ IPv4 address pool: [*] Amazon pool ➔ Allocate ➔ Close.
Now, we have two Elastic IPs with us, which are unassociated.
Step 9: Create a Network Load Balancer (NLB):
At the time of creating Network Load Balancer make sure add two listeners here, one for TCP port 80 and another for TCP port 8080. Also, make sure pick correct AZ in the correct public subnet.
AWS ➔ Services ➔ EC2 ➔ Load Balancers ➔ Create Load Balancer ➔ Network Load Balancer: Create ➔ Name: webshack-NLB➔ Scheme: internet-facing ➔ Listeners: Load Balancer Protocol ➔ (here, we have TCP on port number 80 but we need to add one more for port number 8080) ➔ Add listener ➔ Load Balancer Protocol: TCP ➔ Load Balancer Port: 8080 ➔ Availability Zones ➔ VPC: webshack-vpc (choose your VPC) ➔ (here, select only public subnets in which you created web servers, like I used us-east-1a and us-east-1c) ➔ select subnet ➔ Choose an Elastic IP ➔ provide one Elastic IP ➔ do same for us-east-1c…
Fig: AZ Selection |
…Next ➔ Configure Routing ➔ Target Group: select 'Existing Target Group' from drop-down list ➔ Name: windows-tg (you can select any of them, that would be default and after that we can make any change in it. In my case I am selecting windows target group) ➔ (as we click, this will fill all the information we had ➔ Next ➔ Register Targets (this already have the target) ➔ Next: Review ➔ Create.
We can see it is in provisioning state.
Step 10: Update Listeners in Load Balancer:
If we go to Target Groups we can see the status of Windows Target Group is 'healthy' but Linux Target Group is unused. Also in the Description, we can see Windows has a load balancer but Linux does not have this.
Make sure the status of your Load Balancer should be active.
Select load Balancer ➔ Listeners ➔ (here, we can see that both ports 80 and 8080 are being used for windows-tg. So, we need to update them) ➔ select TCP : 80 listener ➔ Edit ➔ delete default forwarding to Windows Target Group 'windows-tg'…
Fig: Delete Target Group |
…Add action ➔ Forward to ➔ click on 'linux-tg from drop-down list' ➔ Update.
Now, if we go back we can see port no 80 is forwarded to linux-tg and port 8080 is forwarded to windows-tg. Also if we navigate to Target Groups, we can see linux-tg also have Load Balancer listed.
If we click on Target of 'linux-tg' that should be in a healthy state soon.
Step 11: Access website through DNS name:
AWS ➔ Services ➔ EC2 ➔ Load Balancers ➔ Select Load Balancer ➔ Description ➔ copy DNS name ➔ open browser and:Use <DNS name>:80, to access the site from Linux Web Server or
Use <DNS name>:8080 to access the site from Windows Web Server.
CLEANUP:
- Delete Load Balancer
- Delete both Target Groups
- Release Elastic IP
- Terminate both Instances
Enjoy!
No comments:
Post a Comment