TLDR: This blog post provides an in-depth exploration of AWS EC2, covering its definition, advantages, types of instances, regions, and availability zones. It also includes a practical guide on how to create an EC2 instance and deploy Jenkins, making it accessible from the outside world.
In this blog post, we will dive deep into Amazon Web Services (AWS) Elastic Compute Cloud (EC2), one of the most widely used services provided by AWS. Understanding EC2 is crucial for anyone looking to leverage cloud computing for application deployment. We will cover both the theoretical aspects and practical steps to create an EC2 instance, connect to it, and deploy an application, specifically Jenkins, making it accessible from anywhere in the world.
create EC2 instance |
Search ->ec2 -> select instance (lots of cards → resource) -> launch instance |
Name : my-first-instance |
Os : ubuntu |
AMI : V22.04 (free tire -> available for 750 hr/ year) |
Instance type: t2.micro (free tire) |
Key-pair : drop down (create a new key pair) -> name : aws_login -> type: RSA -> format : .pem - - - > create key pair (file downloaded-> aws_login.pem) |
Configure storage : 8gb |
----> launch instance |
login to instance |
Click on created instance -> copy public ip address |
To login to created instance : |
Ssh -i aws_login.Pem ubuntu@<public ip address> | | Chmod 600 aws_login.Pem | | Ssh -i aws_login.Pem ubuntu@<public ip address> | | whoami | | After login it show : private ip address |
install jenkins on ec2 |
Switch to root user: sudo su - |
Upadte package : sudo apt update |
Install java : sudo install openjdk-11-jdk |
Check java is installed : Java --version |
Install jenkins: |
Check Jenkins is installed: systemctl status jenkins |
unable to open issue → http://<public ip address>:8080 |
Created instance -> security (tab) -> security group - > inbound rules - > edit inbound rules |
Add rule ->type: custom tcp -> port: 8080-> source : any where - > save rule |
Now able to open Jenkins ->http//<public ip address>:8080 - > path given to generate password for admin (red color) |
Cat <path> -> password for the Jenkins |
What is EC2?
EC2 stands for Elastic Compute Cloud. It is a service that allows users to request virtual servers, known as EC2 instances, from AWS. These instances are a combination of CPU, RAM, and disk space, essentially functioning as virtual servers. The term "elastic" refers to the ability to scale resources up or down based on demand, making it a flexible solution for various computing needs.
The Components of EC2
Compute: Refers to the virtual server you are requesting from AWS.
Cloud: Indicates that the service is provided over the internet, utilizing AWS's public cloud infrastructure.
Elastic: Highlights the scalability of the service, allowing users to adjust resources as needed.
Why Use EC2?
There are several advantages to using EC2:
Reduced Maintenance: AWS manages the underlying infrastructure, reducing the burden on DevOps engineers and system administrators.
Cost Efficiency: Users pay only for the resources they consume, allowing for significant cost savings compared to maintaining physical servers.
Scalability: Users can easily scale their resources up or down based on demand, ensuring optimal performance without over-provisioning.
Types of EC2 Instances
AWS offers various types of EC2 instances to cater to different workloads:
General Purpose: Balanced resources for a variety of applications.
Compute Optimized: Higher compute power for compute-intensive tasks.
Memory Optimized: Designed for memory-intensive applications.
Storage Optimized: Optimized for high storage throughput.
Accelerated Computing: Utilizes hardware accelerators for specific workloads.
Regions and Availability Zones
AWS has data centers located in multiple geographic regions around the world. Each region consists of multiple availability zones, which are isolated locations within the region. This architecture provides redundancy and high availability for applications. When deploying an EC2 instance, it is essential to choose the appropriate region and availability zone based on factors like latency and data residency requirements.
Practical Guide: Deploying Jenkins on EC2
Now that we have a solid understanding of EC2, let's walk through the steps to create an EC2 instance and deploy Jenkins.
Step 1: Launch an EC2 Instance
Log into the AWS Management Console and navigate to the EC2 dashboard.
Click on "Launch Instance".
Choose an Amazon Machine Image (AMI). For this example, select Ubuntu.
Select the instance type. For free-tier eligibility, choose the T2 micro instance.
Configure instance details, including network settings and storage options.
Create a key pair for secure access to the instance. Download the key pair file (.pem).
Launch the instance.
Step 2: Connect to the EC2 Instance
Open a terminal (or use PuTTY for Windows users).
Change the permissions of the key pair file using the command:
chmod 400 AWS_login.pem
Connect to the instance using SSH:
ssh -i "AWS_login.pem" ubuntu@<public-ip-address>
Step 3: Install Jenkins
Update the package manager:
sudo apt update
Install Java, which is a prerequisite for Jenkins:
sudo apt install openjdk-11-jdk
Install Jenkins by following the official installation instructions for Ubuntu.
Start the Jenkins service:
sudo systemctl start jenkins
Step 4: Access Jenkins
By default, Jenkins runs on port 8080. To access it, you need to modify the security group settings to allow inbound traffic on port 8080.
In the AWS console, navigate to the security group associated with your EC2 instance and add a rule to allow traffic on port 8080 from anywhere.
Open a web browser and enter:
http://<public-ip-address>:8080
Follow the on-screen instructions to complete the Jenkins setup.
Conclusion
In this blog post, we explored the fundamentals of AWS EC2, its advantages, types of instances, and the importance of regions and availability zones. We also walked through a practical example of deploying Jenkins on an EC2 instance, demonstrating how to create an instance, connect to it, and make an application accessible from the outside world. This foundational knowledge is essential for anyone looking to leverage AWS for cloud computing solutions. Happy learning!