• No results found

Starting a virtual server in another data center

In document Amazon Web Services in Action.pdf (Page 101-105)

Using virtual servers: EC2

3.5 Starting a virtual server in another data center

processor : 1

vendor_id : GenuineIntel cpu family : 6

model : 62

model name : Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz stepping : 4

microcode : 0x415

cpu MHz : 2494.066

cache size : 25600 KB [...]

$ free -m

total used free shared buffers cached

Mem: 7479 143 7336 0 6 49

-/+ buffers/cache: 87 7392

Swap: 0 0 0

Your virtual server can use two CPU cores and offers 7,479 MB of memory. Compare this to a single CPU core and 992 MB of memory before you increased the server’s size.

3.5 Starting a virtual server in another data center

AWS offers data centers all over the world. To achieve low latency for requests over the internet, it’s important to choose the closest data center for the majority of your users.

Changing a data center is simple. The Management Console always shows the current data center you’re working in, on the right side of the main navigation. So far, you’ve worked in the data center N. Virginia (US) called us-east-1. To change the data center,

Cleaning up

Terminate the virtual server with instance type m3.large to stop paying for it:

1 Open the EC2 service from the main navigation and select Instances from the submenu.

2 Select the running virtual server by clicking the row in the table.

3 In the Actions menu, choose Instance State > Terminate.

click N. Virginia and select Sydney from the menu. Figure 3.19 shows how to jump to the data center in Sydney called ap-southeast-2.

AWS groups its data centers into these regions:

You can specify the region for most AWS services. The regions are completely indepen-dent of each other; data isn’t transferred between regions. Typically, a region is a col-lection of three or more data centers located in the same area. Those data centers are

Asia Pacific, Tokyo (ap-northeast-1)

EU, Frankfurt (eu-central-1) US East, N. Virginia (us-east-1)

Asia Pacific, Singapore (ap-southeast-1)

EU, Ireland (eu-west-1) US West, N. California (us-west-1)

Asia Pacific, Sydney (ap-southeast-2)

South America, Sao Paulo (sa-east-1)

US West, Oregon (us-west-2)

The region you’re working in

Select Asia Pacific (Sydney) as the region to work in.

Figure 3.19 Changing the data center in the Man-agement Console from N.

Virginia to Sydney

76 CHAPTER 3 Using virtual servers: EC2

well connected and offer the ability to build a highly available infrastructure, as you’ll discover later in this book. Some AWS services, like the content delivery network (CDN) service and the Domain Name System (DNS) service, act globally on top of these regions and even some additional data centers.

After you change to the EC2 service in the Management Console, you may wonder why no key pair is listed in the EC2 overview. You created a key pair for SSH logins in the region N. Virginia (US). But the regions are independent, so you have to create a new key pair for the Sydney region. Follow these steps (see section 1.2 if you need more details):

1 Open the EC2 service from the main navigation and select Key Pairs from the submenu.

2 Click Create Key Pair, and type in sydney as the key pair name.

3 Download and save the key pair.

4 Windows only: Open PuTTYgen and select SSH-2 RSA under Type of Key to Generate. Click Load. Select the sydney.pem file and click Open. Confirm the dialog box. Click Save Private Key.

5 Linux and OS X only: Change the access rights of the file sydney.pem by run-ning chmod 400 sydney.pem in the console.

You’re ready to start a virtual server in the data center in Sydney. Follow these steps to do so:

1 Open the EC2 service from the main navigation and select Instances from the submenu.

2 Click Launch Instance to start a wizard that will guide you through starting a new virtual server.

3 Select the Amazon Linux AMI (HVM) machine image.

4 Choose t2.micro as the instance type, and click Review and Launch to take the shortcut for starting a new virtual server.

5 Click Edit Security Groups to configure the firewall. Change Security Group Name to webserver and Description to HTTP and SSH. Add a rule of type SSH and another of type HTTP. Allow access to SSH and HTTP from anywhere by defining 0.0.0.0/0 as the source for both rules. Your firewall configuration should look like figure 3.20. Click Review and Launch.

6 Click Launch and select sydney as the existing key pair with which to launch your virtual server.

7 Click View Instances to change to the overview of virtual servers, and wait for your new virtual server to start.

You’re finished! A virtual server is running in a data center in Sydney. Let’s proceed with installing a web server on it. To do so, you have to connect to your virtual server via SSH. Grab the current public IP address of your virtual server from the details page.

Open a terminal and type ssh -i $PathToKey/sydney.pem ec2-user@$PublicIp with

$PathToKey replaced by the path to the key file sydney.pem you downloaded and

$PublicIp replaced by the public IP address from the details of your virtual server.

Answer Yes to the security alert regarding the authenticity of the new host.

After establishing a SSH session, you can install a default web server by executing sudo yum install httpd -y. To start the web server, type sudo service httpd start and press Return to execute the command. Your web browser should show a place-holder site if you open http://$PublicIp with $PublicIp replaced by the public IP address of your virtual server.

Change the name and description.

Add a rule to allow HTTP requests from anywhere.

Click here to proceed.

Figure 3.20 Configuring the firewall for a web server in Sydney

78 CHAPTER 3 Using virtual servers: EC2

NOTE You’re using two different operating systems in this chapter. You started with a virtual server based on Ubuntu at the beginning of the chapter. Now you’re using Amazon Linux, a distribution based on Red Hat Enterprise Linux.

That’s why you have to execute different commands to install software.

Ubuntu uses apt-get, and Amazon Linux is using yum to do so.

Next, you’ll attach a fixed public IP address to the virtual server.

In document Amazon Web Services in Action.pdf (Page 101-105)