AWS Ec2(Elastic Cloud Compute)

AWS Ec2(Elastic Cloud Compute)

  1. Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers.

  2. EC2 represents Elastic Cloud Compute.

  3. Here Compute means we are requesting AWS to provide a compute instance comprising CPU,RAM and DIsk. We are eventually requesting for Virtual Server.

  4. Here cloud means we are getting a cloud virtual machine.

  5. Elastic here is used with the service to determine that the service can be scaled up or down which means it is elastic in nature.

  6. So here EC2 is the virtual machine/server or a compute system over a cloud given by AWS

Advantage of EC2

Imagine we have our own servers and we create our own virtual machines. These will be in number of thousands. But after creating we have to upgrade this virtual machines, check security issues ,multiple crashes. This can be a tedous task. Instead AWS takes care of all this and provide us the virtual machine.This will also reduce the cost.

Types of EC2 instance

  1. General purpose EC2 Instance

    These EC2 instance provide balance of compute , memory and network resources. These can be used for a variety of diverse workloads like webservers.

  2. Compute Optimised EC2 Instance

    These are used for applications requiring high performance processing

  3. Storage Optimised EC2 Instance

    These are used for applications that require high, sequential read-and-write access to large datasets

  4. Memory Optimised EC2 Instance

    These Memory Optimized instances are designed to handle memory-intensive workloads

  5. Accelerated EC2 Instance

    Accelerated computing instances use hardware accelerators, or co-processors, to perform functions, such as floating point number calculations, graphics processing, or data pattern matching, more efficiently than is possible in software running on CPUs.

AWS EC2 Regions and Zones

Amazon EC2 is hosted in multiple locations world-wide. Each Region is a separate geographic area. Availability Zones are multiple, isolated locations within each Region. Each Region is designed to be isolated from the other Regions. This achieves the greatest possible fault tolerance and stability.

Creating EC2 Instance

  1. Login into AWS console as root user

  2. Search for EC2 in search bar

  3. Click on Instances

  4. Then click on Launch Instance at right hand side

  5. Name the Web server, and choose the OS Image as Ubunutu. Choose instance type as Free Tier.

  6. Create a new Key Login Pair .

    Remember we need this to access our instance via terminal. This is a key value pair. It is a combination of public private key. Instance have public key and we need private key to login. Name the Key pair name and keep default settings. A pem file will be downloaded. Keep it in an accessible location.

  7. Keep other settings as it is and click on Launch Instance. Within couple of minutes we will get our instance running.

  8. Now navigate back to Instances and click on Instance ID. We will have public and private ip address. We will use public ip address to login into instance

Login to EC2 instance via Terminal

Download Mobaexterm or Putty.

  1. Launch the application(Download Mobaexterm or Putty)

  2. I have my pem file in downloads. So I ran below command and after @ I used my public IP address from console. I changed the permission of the file.

  3. ```plaintext  04/07/2023   20:12.18   /home/mobaxterm  chmod 600 C:/Users/vijay/Downloads ✓

     04/07/2023   20:13.06   /home/mobaxterm  ssh -i C:/Users/vijay/Downloads/test42.pem ubuntu@3.135.208.138 Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.19.0-1025-aws x86_64)

    • Documentation: help.ubuntu.com
    • Management: landscape.canonical.com
    • Support: ubuntu.com/advantage

      System information as of Tue Jul 4 14:43:13 UTC 2023

      System load: 0.0078125 Processes: 98 Usage of /: 20.8% of 7.57GB Users logged in: 0 Memory usage: 25% IPv4 address for eth0: 172.31.10.245 Swap usage: 0%

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates. See ubuntu.com/esm or run: sudo pro status

The list of available updates is more than a week old. To check for new updates run: sudo apt update

Last login: Tue Jul 4 14:42:12 2023 from 103.66.214.251 To run a command as administrator (user "root"), use "sudo ". See "man sudo_root" for details.

ubuntu@ip-172-31-10-245:~$


4. And now we are inside ubuntu.


## Deploy Jenkins on AWS

1. Beforehand we need to update packages in Ubuntu.

    ```plaintext
    sudo apt update
  1. Now we need to instal Java

     sudo apt install openjdk-11-jdk
    
  2. To check if java is installed or not

    java --version

    If it return below output then it is installed

  3. Visit Jenkins official website-> Download -> Ubuntu. Copy the command in Weekly release section and run it.

     curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
       /usr/share/keyrings/jenkins-keyring.asc > /dev/null
     echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
       https://pkg.jenkins.io/debian binary/ | sudo tee \
       /etc/apt/sources.list.d/jenkins.list > /dev/null
     sudo apt-get update
     sudo apt-get install jenkins
    
  4. To check if jenkins is installed or not run below command

    
     ubuntu@ip-172-31-10-245:~$ sudo systemctl status jenkins
    

The port number of Jenkins is 8080. We need to open the port 8080 so that we can access Jenkins through EC2 server.

  1. Click on id of our instance.

  2. Navigate to Security tab

  3. Click on security group -> Inbound traffic rules -> Edit inbound rules

    1. Add a new rule

    2. And Save the rule

  4. Now run the URL in browser

  5. http:// <YOUR_PUBLIC_IP_ADDRESS> :8080

  6. This will show that jenkins is accessible .

Resources