Prerequisite

Before we start, we need to spin up two instances running Amazon Linux and put them in two availability zones. This way, we will demonstrate how to make an application highly available:

  1. We can follow the procedure to build an EC2 instance from the Building an EC2 instance in AWS section in Chapter 5, Managing Servers on AWS with Elastic Compute Cloud. Once created, we should see two instances running in two availability zones:

  1. We will also create a new security group to open port 80 on those instances, as we will be serving a simple HTTP site to show the server's name in the response:

  1. Choose Create Security Group, specify a name and description for the security group, and attach it to the VPC in which the instances are running. After you have created the security group, create a rule of type HTTP and source from anywhere:

  1. In the EC2 Management Console, select the Instances and choose Actions | Networking | Change Security Groups:

  1. Select the newly created security group:

  1. To verify the current security group associations of each instance, we can select the instance and check the Security groups section in the Description:

  1. To create a simple HTTP response on port 80, we will connect to each instance and run a simple command on each of the servers. For webserver1, run the following command:
sudo su
nohup sh -c "mkdir test && cd test && echo '<html>Hello from webserver1</html>' > index.html && python -m SimpleHTTPServer 80" &

The output for it should look like this:

  1. For webserver2, we just need to change the text to the following:
sudo su
nohup sh -c "mkdir test && cd test && echo '<html>Hello from webserver2</html>' > index.html && python -m SimpleHTTPServer 80" &

And the result should look like this:

  1. After we have completed the previous steps, browsing to the instance IP addresses should give us the following responses. This is on webserver1:

And this is on webserver2:

By setting up two instances with two different responses, we will be able to see the load balancer in action. When the load balancer chooses webserver1, it will respond with its name and when the content is served from webserver2, its name will be visible in the response. With this, we can be assured that the content is being delivered from two different servers in two different availability zones, and that our application is highly available.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.36.194