Linux | Cloud | DevOps | Scripting

Breaking

Monday, 1 July 2019

Move Traffic of Your Site towards a Private Host


Route53:

Amazon Route 53 is a highly available and scalable cloud Domain Name System (DNS) web service. With Amazon Route 53, we can create and manage our public DNS records. Like a phone book, Route 53 lets you manage the IP addresses listed for our domain names in the Internet's DNS phone book.

Route 53
Fig: Route 53

Benefits of Route 53:

  1. Highly available and reliable
  2. Flexible
  3. Designed for use with other Amazon Web Services
  4. Fast
  5. Cost-effective
  6. Secure
  7. Scalable 

Scenario:

We have a running Web Server from one instance. But in case if our website is down from this instance, then DNS traffic should move towards another node.

In this practical, I am using S3 bucket for Secondary Web Server but you can use an instance also.

For this we need to follow the steps:
  1. Create a Web Server
  2. Allocate and associate an Elastic IP to this Web Server
  3. Create a static website
  4. Create a condition for Health Checkup in Route 53 and associate it to Primary Web Server
  5. Associate it with the Primary Web Server
  6. Allocate Secondary Web Server to the Hosted Zone
  7. Stop Primary Web Server instance and verify your website

Step 1: Create a Web Server:

To create a Web Server, kindly follow the steps from the below-mentioned web URL:

https://redhatpanacia.blogspot.com/2019/07/public-hosted-zone.html

I named this instance as 'lin-web-server'. Use below-mentioned script for Web Server:

          #!/bin/bash
          yum install -y httpd
          echo "This site is coming from Amazon EC2 instance" >> /var/www/html/index.html
          service httpd restart
          systemctl enable httpd

In this script, we are using matter as "This site is coming from Amazon EC2 instance". When we create a site in S3 bucket, we use matter as "This site is coming from S3 bucket", so that we could recognize from where we are getting webpage. But in industry, both of the sites should be same.

Step 2: Allocate and associate an Elastic IP to this Web Server:

AWS ➔ Services ➔ EC2 ➔ Elastic IPs ➔ Allocate new address ➔ [*] Amazon pool ➔ Allocate ➔ Close.

Now Associate:

Select new allocated Elastic IP ➔ Actions ➔ Associate address ➔ Resource type: [*] Instance ➔ Instance: select lin-web-server ➔ Private IP: select lin-web-server's private IP ➔ Associate ➔ Close.

Step 3: Create a Static Website:

To create a Static Website, kindly follow the steps from the below-mentioned web URL:

https://redhatpanacia.blogspot.com/p/static-web-hosting.html

Here, in index.html, kindly use matter as "This site is coming from S3 bucket".

Step 4: Create a condition for Health Checkup in Route 53 and associate it to Primary Web Server:

AWS ➔ Services ➔ Route 53 ➔ Health Checks ➔ Create health check ➔ Name: webshack.cf (can be any name) ➔ What to monitor: [*] Endpoint ➔ Specify endpoint by: [*] IP address ➔ Protocol: HTTP ➔ IP address: (provide IP of EC2 Web Server, which is a primary webserver) ➔ Hostname: (you can also provide hostname) ➔ Port: 80 ➔ Path: leave blank for default (but if you changed location of index.html or you renamed index.html, then provide full path) ➔ Next ➔ Cloud alarm: [*] No (select yes, if you want to use Cloud alarm ➔ Create health check.

But this is in Unknown status right now.

Step 5: Associate it with the Primary Web Server:

Now, navigate to Hosted zone and make changes on A-record type:

AWS ➔ Services ➔ Route 53 ➔ Hosted zones ➔ Click on Hosted zone, like mine is 'webshack.cf' ➔ click on A-record ➔ change Routing Policy from 'Simple' to 'Failover' ➔ Failover Record Type: [*] Primary ➔ Associate with Health Check: [*] Yes ➔  Health Check to Associate: select your created Health check ➔ Save Record Set.

Now go back to the Health Check and you can see it is in healthy status now, means Health Check is associated now.

Step 6: Allocate Secondary Web Server to the Hosted Zone:

AWS ➔ Services ➔ Route 53 ➔ Hosted zones ➔ Click on your Hosted zone ➔ Create Record Set ➔ Name: www ➔ Type: A-IPv4 address ➔ Alias: [*] Yes ➔ Alias Target: select S3 bucket from drop-down list ➔ Routing Policy: Failover ➔ Failover Record Type: [*] Secondary ➔ (No need to provide any Health Checkup, because there is no need of any health check for S3 bucket) ➔ Create.

Step 7: Stop Primary Web Server instance and verify your website:

AWS ➔ Services ➔ EC2 ➔ Select 'lin-web-server' instance ➔ Actions ➔Instance State ➔ Stop.
This will stop the instance. Now, go to the browser and try to access your domain. This will result as 'This site is coming from S3 bucket'.

Enjoy!




No comments:

Post a Comment

Pages