In this article, we have three tasks. 1. Use the Amazon Management Console to create an EC2 instance. Second, use the local command line tool to remotely log on to the EC2 instance. Third: create a web service on the EC2 instance and access the Web service through a public domain name.
If you do not have an AWS account, you can use the free lab provided by qwiklabs for this exercise. The address is https://run.qwiklabs.com.
Log on to the Amazon AWS Service Management Console and select the EC2 service.
Then you can go to the EC2 control panel.
Click the above buttonLaunch Instance
To create a new EC2 instance.
First, you must select the machine's image file AMI (Amazon machine image). There are various Linux distributions and Windows systems. In this experiment, we select the first one, Amazon Linux AMI, and Amazon's own Linux release.
Then select the machine type. The performance of different types of machines varies with the charging standard. Everything is determined based on your needs. Select the first one, which is the cheapest.
Then you have two options: ClickReview and Launch
Start the new machine directly, use the default values for other parameters, and clickNext:Configure Instance Details
Customize other configurations. Here we select the second button until Step 6: Configure Security Group.
You can use an existing security group or create a new one. In a security group, you can set a series of policies to manage access between the instance and the outside world.
Because we need to remotely log on to this instance and the instance needs to provide HTTP services, we need to open ports 22 and 80. Port 22 is open by default, and port 80 needs to be opened manually. ClickAdd Role
Button and add a new role.
ClickLaunch
Button, a page will pop up asking you to set key pair.
This key pair is used to establish a secure connection with the instance. Amazon stores a public key and stores a private key locally. to connect to the instance, you must provide a private key. Here we choose to create a new key pair, named awsworkshop, and save it to the local device. It will be used to SSH to the instance later.
ClickLaunch Instances
The instance is initialized.
ClickView Instances
To view the newly created instance.
It usually takes 3 to 5 minutes to initialize the new instance. You can view information about the instance. Amazon assigns a public IP address and a public DNS domain name to the instance. You need to use them later.
Wait untilInstance Status
Isrunning
Then, we can perform the second task, that is, remotely connect to the instance.
Open your favorite terminal, and then upgrade the permissions of the saved PEM file.
1 |
$: chmod 600 ~/Downloads/awsworkshop.pem
|
Then find the public IP of the instance on the AWS control panel and SSH to the instance using the ec2-user username.
1 |
$: ssh [email protected] -i ~/Downloads/awsworkshop.pem
|
You can connect to the remote instance after waiting.
12 |
[[email protected] ~]$ whoec2-user pts/0 2014-07-26 06:38 (123-243-183-184.static.tpgi.com.au)
|
How is it? Everything is simple, right?
Next we will conduct the last task of this experiment and build a web server on this remote instance.
After SSH to the instance, run the following command.
1 |
$: sudo yum install httpd
|
This command is used to install the httpd server of Apache.
Then jump/var/www/html
Directory, and create a newindex.html
.
12 |
$: cd /var/www/html$: sudo touch index.html
|
Use the editor you used to input an HTML document in the file and save it.
Start the web server.
1 |
$: sudo service httpd start
|
As a result, find the public DNS from the control panel of the EC2 instance and paste it into the browser to access the Web service provided by the instance.
All three tasks are completed. I hope you will enjoy this EC2 tour.