官术网_书友最值得收藏!

  • Mastering Symfony
  • Sohail Salehi
  • 688字
  • 2021-07-16 11:29:01

Elastic Compute Cloud

Amazon Elastic Compute Cloud (EC2) is the largest public cloud in the world and we will use EC2 to set up our CI server.

Assuming that you have already created your free account on AWS, you should be able to see the console area when you log in.

As you can see in the following image, it is packed with loads of components, and if this is the first time you are here, it might look overwhelming. Don't worry, we only need two of these services for this chapter:

Elastic Compute Cloud

Creating a new instance

Our CI server is basically a virtual machine running Linux, which, in AWS terminology, is called an instance. So, from now on, when you see the term instance, it means a virtual machine on the cloud. To create your first instance, follow these steps:

  1. Under the Compute & Networking option, click on EC2.
  2. Before doing anything, you need to select the right region for better performance. In the upper-right hand corner of the page, there is a drop-down list where you can select the closest area to you, as shown in the following screenshot:
    Creating a new instance
  3. Now, click on the big blue button saying Launch Instance and select the latest version of the Ubuntu server. Pay attention; some options have a Free tier eligible label and some don't. After selecting EC2, a validation from Amazon is required. This validation could take from several minutes to days:
    Creating a new instance
  4. As you can see in the following screenshot, only t2.micro is free. Select this plan and click on Next: Configure Instance Details.
    Creating a new instance
  5. The next two steps are configuration (3. Configure Instance) and adding storage (4. Add Storage). Simply accept the default settings and move on to Step 5: Tag Instance. Here, we will choose a Tag name for our virtual machine. Enter the name Mava in the Value field and proceed to the next step:
    Creating a new instance
  6. This step is where you set up the firewall for your CI server and define which ports should be open to the outside world. In the Security group name field, type Mava. We need SSH and HTTP access to our server, so click on the Add Rule button, choose HTTP, and press the Review and Launch button:
    Creating a new instance
  7. When you press the Review and Launch button, as shown in the following screenshot, it asks for a public and private key pair in order to access our EC2 instance. Choose Create a new key pair. Type the name mava-keys for it. Now you can click on the Launch Instances button. It takes a few seconds to generate the instance and when it is finished, you can click on the View Instances button to see it. Be patient as it takes a while to change the status from pending to running:
    Creating a new instance

    Tip

    Do not lose your key. If you lose it, you have to delete your instance completely and start over again. Due to security reasons, Amazon doesn't keep a backup of your key.

  8. While it is in the running mode, click on your instance and copy the Public DNS address:
    Creating a new instance
  9. Right now, you have enough information to connect to your EC2 instance:
    ssh -i ~/Downloads/mava-keys.pem ubuntu@ec2-54-79-31-45.ap-southeast-2.compute.amazonaws.com
    

    However, this is a very long command and not very safe as well. First, we want to make sure that only we have read and write access to our key. So fire a terminal window, copy the instance key to your .ssh folder, and set the permission as follows:

    $ mv ~/Downloads/mava-keys.pem ~/.ssh/
    $ chmod 400 ~/.ssh/mava-keys.pem
    
  10. Now, for more convenience, let's create an alias for that long ssh command. Open the .ssh/config file and add the following contents to it. Remember that for Hostname, you have to add your own Public DNS value that you copied from step 8:
    Host ec2
      Hostname ec2-54-79-31-45.ap-southeast-2.compute.amazonaws.com
      User          ubuntu
      IdentityFile  ~/.ssh/mava-keys.pem
  11. Now you can connect to your instance via this short command:
    ssh ec2
    
  12. For the first time, you will be prompted with the following:
    Are you sure you want to continue connecting (yes/no)? Yes
    
  13. Answer Yes and congratulations! You are now connected to your EC2 instance on the Amazon cloud:
    ubuntu@ip-172-31-29-153:~$
    
主站蜘蛛池模板: 拜泉县| 钦州市| 长海县| 华安县| 上栗县| 福安市| 镇赉县| 达日县| 建始县| 建昌县| 拉萨市| 安仁县| 景德镇市| 宁化县| 剑川县| 原阳县| 藁城市| 平舆县| 诏安县| 三穗县| 嫩江县| 云阳县| 和龙市| 余江县| 永仁县| 行唐县| 扎兰屯市| 柯坪县| 昌图县| 龙岩市| 安乡县| 县级市| 梁河县| 靖边县| 错那县| 宜川县| 弋阳县| 东乌珠穆沁旗| 奉化市| 南康市| 临汾市|