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

  • 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:~$
    
主站蜘蛛池模板: 浑源县| 康平县| 方城县| 乐安县| 崇信县| 育儿| 花莲县| 兰西县| 乐都县| 双辽市| 长顺县| 巢湖市| 青浦区| 交城县| 双鸭山市| 长武县| 余姚市| 宜宾市| 栾城县| 兴隆县| 平江县| 越西县| 烟台市| 泗阳县| 古蔺县| 井陉县| 寿阳县| 万全县| 宁津县| 凤翔县| 琼结县| 尼勒克县| 红安县| 林西县| 峨眉山市| 石首市| 垫江县| 兴和县| 青神县| 禹州市| 五台县|