The Ops Community ⚙️

Cover image for Set Up VM For Jenkins Master and How To Install
Nurul Ramadhona
Nurul Ramadhona

Posted on • Updated on

Set Up VM For Jenkins Master and How To Install

Hi everyone! It's been a while since I joined this community. So, yesterday I started to learn about Jenkins. Maybe you're familiar with it, especially for DevOps and maybe it's too late for me :) but yeah, I'm in progress now.

Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software

Source: Jenkins Official Website

Then, instead of learning by myself. I thought about what if I share about what I'm currently learning. So, maybe I can get some suggestions to make me better and I hope I'll get it from you. Feel free to leave a comment.

Alright! The first step before we install Jenkins, we have to set up virtual machine where Jenkins will be installed. So, we wouldn't go with localhost but host the VM on cloud. I used AWS EC2 instance, but you can use anywhere that you want. I'll tell you the main points of setting up VM for Jenkins in a second below.

1. Create Security Group (Firewall Rules)
Because we host on the cloud. So, we have to allow two ports as we need. Port 22 to remote host and another port for Jenkins. On this first try, I won't change anything. Then, I'll use the default port which is 8080.

$ aws ec2 create-security-group --description "allow ssh and default jenkins port" --group-name jenkins
GroupId: sg-0043147ddc775c62d
$ aws ec2 authorize-security-group-ingress --group-name jenkins --protocol tcp --port 22 --cidr 0.0.0.0/0
Return: true
$ aws ec2 authorize-security-group-ingress --group-name jenkins --protocol tcp --port 8080 --cidr 0.0.0.0/0
Return: true
Enter fullscreen mode Exit fullscreen mode

2. Create VM
Here I use Ubuntu server with newly created security group.

$ aws ec2 run-instances --image-id ami-0c1460efd8855de7c --count 1 --instance-type t3.micro --key-name ubuntu --security-group-ids sg-0043147ddc775c62d

$ aws ec2 describe-instances --query 'Reservations[].Instances[].{PublicIP:PublicIpAddress, ID:InstanceId}'
- ID: i-0bd3d9b34302fdbe0
  PublicIP: 108.137.62.173

$ ssh ubuntu@108.137.62.173
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-1004-aws x86_64)

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

  System information as of Thu Jun  9 11:15:28 UTC 2022

  System load:  0.013671875       Processes:             110
  Usage of /:   18.9% of 7.58GB   Users logged in:       0
  Memory usage: 20%               IPv4 address for ens5: 172.31.17.9
  Swap usage:   0%

ubuntu@ip-172-31-17-9:~$
Enter fullscreen mode Exit fullscreen mode

3. Pre-install Jenkins
We need some packages to be installed to support our Jenkins operation like integrating with GitHub and many more. The two important things are Git and Java. Because Git already installed by default on EC2 Ubuntu, I'll continue to install Java.
(I don't know you have same condition as me or not but if Git is not installed yet, you can run $ sudo apt install git as usual)

ubuntu@ip-172-31-17-9:~$ javac --version
Command 'javac' not found, but can be installed with:
sudo apt install default-jdk              # version 2:1.11-72build2, or
sudo apt install openjdk-11-jdk-headless  # version 11.0.14.1+1-0ubuntu1
sudo apt install ecj                      # version 3.16.0-1
sudo apt install openjdk-17-jdk-headless  # version 17.0.2+8-1
sudo apt install openjdk-18-jdk-headless  # version 18~36ea-1
sudo apt install openjdk-8-jdk-headless   # version 8u312-b07-0ubuntu1
ubuntu@ip-172-31-17-9:~$ sudo apt install openjdk-11-jdk-headless
ubuntu@ip-172-31-17-9:~$ javac --version
javac 11.0.14.1
Enter fullscreen mode Exit fullscreen mode

4. Download and Install Jenkins

ubuntu@ip-172-31-17-9:~$ wget https://get.jenkins.io/war-stable/2.332.3/jenkins.war
HTTP request sent, awaiting response... 200 OK
Length: 94928325 (91M) [application/java-archive]
Saving to: ‘jenkins.war’

jenkins.war         100%[===================>]  90.53M  6.88MB/s    in 13s     

2022-06-09 11:16:08 (7.03 MB/s) - ‘jenkins.war’ saved [94928325/94928325]

ubuntu@ip-172-31-17-9:~$ ls
jenkins.war
ubuntu@ip-172-31-17-9:~$ java -jar jenkins.war &
Enter fullscreen mode Exit fullscreen mode

5. Access Jenkins Dashboard
Go to http://your-ip:port, for example: http://108.137.62.173:8080. Then, you'll be asked to enter password. The password is placed on web root directory or it'll be shown as you can see below. In this step, we're not going to install any plugin cause I wanna do that only when we need it. I'll tell you on the next step later.

Jenkins Dashboard 1

Jenkins Dashboard 2

Jenkins Dashboard 3

Jenkins Dashboard 4

Jenkins Dashboard 5

Jenkins Dashboard 6

Jenkins Dashboard 7

Jenkins Dashboard 8

Alright, that's it for now! Any feedback are very welcome and thank you for coming. Follow me to get notified when new post is published by me! Thank you.

Let's continue to the next part!

Top comments (2)

Collapse
 
gjorgivarelov profile image
gjorgivarelov

Why did you choose Jenkins? Have you explored Ansible? Why storing your Jenkins VM in the cloud and not local?

Collapse
 
nurulramadhona profile image
Nurul Ramadhona Author

Hi @gjorgivarelov! Here are what I can answer:

Q: Why did you choose Jenkins?
A: Because I found that it's become popular tool to use and I can say I enjoyed some features that I already know. I haven't tried any other tools, so I can't make a comparison and really know why I should choose Jenkins over the other ones.
Q: Have you explored Ansible?
A: Yes, I've explored. If you see my posts here and on DEV too, I talk a lot about ansible.
Q: Why storing your Jenkins VM in the cloud and not local?
A: Because Jenkins should be on independent host, I think. It's totally different with ansible which anyone can install it on their localhost and sync the code with Git for instance. Then, since I learn alone only by using my single laptop with limited specs :) I don't have some resources to use when I wanted to learn about add node, but it's possible to be stored in local if I work for a company that has on-premise server.