Installing Jenkins on an EC2 Instance: A Step-by-Step Guide

Installing Jenkins on an EC2 Instance: A Step-by-Step Guide

ยท

3 min read

This blog post walks you through the process of installing Jenkins on a freshly launched EC2 instance. We'll cover everything from setting up the instance to accessing the Jenkins interface.

Prerequisites

  • An AWS account with access to the Management Console

  • Basic understanding of Linux commands

Launching the EC2 Instance

  1. Open the AWS Management Console and navigate to the EC2 service.

  2. Click on "Launch Instance".

  3. Choose an Ubuntu AMI (Amazon Machine Image) version 20.04 (LTS).

  4. Select an instance type. T2 Micro is sufficient for basic use, but you can upgrade to T2 Small if needed.

  5. Create a new key pair for SSH access. Download the private key and keep it secure.

  6. Configure the Security Group:

    • Allow inbound traffic on port 22 for SSH access.

    • Allow inbound traffic on port 8080 for Jenkins access.

  7. Launch the instance.

Installing Jenkins

  1. Connect to the EC2 instance via SSH using the downloaded private key.

  2. Update package lists: sudo apt update

  3. Install Java JDK 11: sudo apt install openjdk-11-jdk

  4. Add the Jenkins repository key:

     sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
       https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
    
  5. Create the Jenkins repository file:

     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
    
  6. Update package lists again: sudo apt update

  7. Install Jenkins: sudo apt install jenkins

Starting and Verifying Jenkins

  1. Check the Jenkins service status: sudo systemctl status jenkins

  2. The output should show Jenkins as "active (running)".

Accessing Jenkins

  1. Open a web browser and navigate to http://<your_public_IP>:8080. Replace <your_public_IP> with the actual public IP address of your EC2 instance.

  2. Locate the initial password file path from the Jenkins service status output.

  3. Use cat command to view the password: cat <password_file_path>

  4. Paste the password into the Jenkins login screen.

Installing Plugins (Optional)

  1. Jenkins offers a wide range of plugins for various functionalities.

  2. You can explore the available plugins and install the ones you need for your specific use case.

Creating User

  1. After installing the plugins, we have to create a user.

  2. In the next step, we need to configure the root URL for Jenkins.

  3. Once done, we are ready to create our first job.

Creating Your First Job

  1. We'll cover creating jobs (manual and pipeline) in detail in future lectures.

  2. This blog post focuses on the installation process.

Important Notes

  • The public IP address of your EC2 instance will change when you stop and restart it.

  • Make sure to update the security group rules if you plan to access Jenkins from a different IP address.

  • Remember the username and password you created during the initial setup.

This blog post provides a basic understanding of installing Jenkins on an EC2 instance. We'll delve deeper into creating and managing Jenkins jobs in future posts.

ย