Skip to main content

Command Palette

Search for a command to run...

Install Jenkins in EC2 Instance using User Data Script

Published
3 min readView as Markdown
Install Jenkins in EC2 Instance using User Data Script
S
I'm energetic, ambitious person who has developed a mature and responsible approach to any task that I undertake, or situation that I am presented with. I am excellent at working with others to achieve a certain objective on time and with excellence. Customer Engineer| Al/ ML |AI Infrastructure | Cloud Migration |Technical Solution| Vertex AI| Cloud Database |Cloud Networking |DevOps Engineer| Technical Blogger| Generative AI| Google Cloud Ready Facilitator 🌐Linux Linux Professional Institute Certificate Technical Writer \ Cloud Networking Cloud Computing \ Cloud Infrastructure Cloud Consultant \ Customer Engineer 🌐Virtualization - VMware, vSphere, vCenter Server 🌐Programming Skill Technical Skills Proficiency in languages like Java, Python, Scala, or JavaScript. System Administration: Experience with Linux/Unix systems, Windows Server. Networking: Understanding of network protocols, routing, VPC, Subnets, Firewalls, VPNs, Load Balancers, switching, and firewall configurations. Cloud Platforms: Experience with AWS, Azure, or Google Cloud Platform. Databases: Knowledge of SQL and NoSQL databases like MySQL, PostgreSQL, MongoDB. Scripting: Ability to write scripts for automation using Bash, PowerShell, or similar. Monitoring and Logging: Familiarity with tools like Nagios, Prometheus, Grafana, ELK Stack. Configuration Management: Experience with tools like Ansible, Puppet, Chef. DevOps: Knowledge of CI/CD pipelines, Jenkins, Docker, Kubernetes. Security: Understanding of security best practices and tools, Cloud security best practices, IAM, Security Groups, Compliance. Infrastructure as Code: Terraform, CloudFormation, Ansible Compute Services: EC2, GCE, Azure VMs. Storage Solutions: S3, GCS Customer Service Skills:- Communication: Strong verbal and written communication skills. Problem-Solving: Ability to diagnose and resolve technical issues efficiently. Interpersonal Skills: Building and maintaining relationships with clients. Training and Education: Ability to conduct training sessions for clients. Project Management: Managing customer projects and ensuring timely delivery. Knowledge/experience in configuring and supporting devices such as Cisco, Juniper, Checkpoint, etc. Knowledge Cloud Migration, Presale, Data Center relocation, Go-to-Market Strategy. Certifications: AWS Certified Solutions Architect Microsoft Certified: Azure Solutions Architect Expert Google Professional Cloud Architect Certified Kubernetes Administrator (CKA)

Amazon Elastic Compute Cloud(EC2) is a web service that provides secure, resizable computing capacity in the cloud. It allows users to rent virtual computers, launch as many or as few virtual servers as needed, configure security and networking, and manage storage. Amazon EC2 enables you to scale up or down to handle changes in requirements or spikes in popularity, reducing your need to forecast traffic.

User data script is the easiest and most popular way to send instructions to an instance at launch. You should allow a few minutes of extra time for the tasks to complete before you test that the user script has finished successfully.

When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts.

So, here I am using the Ubuntu system for installing Jenkins:

1. Login into AWS and search for EC2 in services

Click on EC2 and explore the dashboard.

tempsnip.png

2. Launch an EC2 Instance

For creating a new instance, click on instances and choose Launch instances from the dropdown.

tempsnip.png

3. Configure EC2

Enter the name of your server like "Jenkins server" and choose Amazon Machine Image(AMI). An AMI is a template that contains a software configuration (for example, an operating system, an application server, and applications). In my case, I am selecting Ubuntu Server 22.04.

tempsnip.png

4. Create new key pair

Choose the instance type eligible for the free tier ( t2.micro) or higher instance type based on your server requirements. Click Create new key pair.

tempsnip.png

The key pair will allow you to SSH into the machine you just created. Create the key pair and download it, make sure to keep it safe as you will not be able to download it again. Choose key pair type as RSA and .pem as private key format and click Create key pair.

image.png

5. Configure network settings and Storage

Keep VPC and Subnet defaults in the network setting. Edit the security group and allow HTTP traffic from the internet at port 8080, by default Jenkins runs on port 8080. AllowSSH at port 22 from anywhere. Select the amount of storage you want for your system, 8 GB is eligible for the free tier.

image.png

6. Advance details

Expand advance details section and scroll to the end. Copy and paste the user data script to install Jenkins at the time of launch. Lastly, click Launch instance in the bottom right corner.

#!/bin/bash
sudo apt update -y
sudo apt install openjdk-11-jdk -y
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.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-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins -y

tempsnip.png

Your instance is running now, In order to access Jenkins in your local click the instance id of a running instance.

image.png

Click on your instance id and copy Public IPv4 address.

tempsnip.png

6. Access Jenkins

Go to your browser and search with Public IPv4 address:8080.

image.png

7. Connect to your instance

Click the connect option in your instance menu. Go to the EC2 Instance Connect option and click connect.

tempsnip.png

Copy the path from the browser and cat into the EC2 terminal as shown below. Be the root user first:

  • sudo -i

  • cat /var/lib/jenkins/secrets/initialAdminPassword

Copy the password and paste it into the Jenkins console. Install suggested plugins. Set your username and password for future login.

tempsnip.png

Finally, start using the jenkins.

image.png

19 views

More from this blog

C

CloudGrad

96 posts