I previously wrote an article on how to install Jenkins on Azure. I’ve also blogged about following related topics.
- How to Install Jenkins Slave as Windows Service
- How to Configure Jenkins on Azure
- Running Jenkins on SSL on Azure
- Jenkins Slave Failed to Validate a Server Certificate
Now I’m going to try to write about Jenkins installation and configuration on AWS. I obviously don’t want to just reinvent the wheel or completely do things wrong, so I did my search and I found a documentation here. I’m going to refer to it and work on an instance actually on my personal AWS account.
Create EC2 (VM) Instance
Let’s create a VM instance to host the Jenkins master. I’m going to assume that you’ve already set up an AWS account.
With your browser, navigate to aws.com and click on EC2 under All services –> Compute.
Make sure to select Oregon as the region at the upper right area.
Click Launch Instance button.
I’m going to select “Amazon Linux 2 AMI (HVM), SSD Volume Type”.
In the next step, I’m going to select the VM template of t2 micro of vCPUs 1 and 1 GB memory. I think it’s enough to run an instance of Jenkins master but I would not select this configuration in actual enterprise environments for its sheer size to scale. Click Review and Launch button.
Click Launch button in the next step.
You are now prompted to select an existing key pair or create a new one. I am creating a new one for this one and naming it jenkins_master. Make sure to download it to your desktop for later use for your SSH session. Finally click Launch instances button.
SSH into the Created Instance
Let’s SSH into the created instance. First, navigate to EC2 -> Instances and select the instance you just created. And click Connect button.
By clicking Connect button, you will see the instruction on how to SSH into the instance like the following.
Open terminal and navigate to the directory where you store the .pem file and copy and paste the command in the Example: section.
ssh -i "jenkins_master.pem" firstname.lastname@example.org
Once the command is successful, you will see a screen like the following.
As you can see, Amazon Linux is an offspring of CentOS so run
sudo yum -y update to update the packages.
Installing Jenkins Master
Now we can install Jenkins master. The latest version of Java supported by Jenkins is Java 11. I’m going to install OpenJDK 11 first.
$ sudo amazon-linux-extras install java-openjdk11
To check if Open JDK has been installed, execute the following command.
$ java --version
Now we are going to import Jenkins repo so that we can use yum to install Jenkins.
$ curl --silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo | sudo tee /etc/yum.repos.d/jenkins.repo $ sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
Now execute the command to install Jenkins.
sudo yum install jenkins
$ sudo systemctl start jenkins
Make sure that the Jenkins daemon starts by itself after reboot.
$ sudo systemctl enable jenkins
See if the Jenkins process is up and running by executing the following command.
You should see something like the following image.
$ ps aux | grep jenkins
–httpPort=8080 indicates that Jenkins master is listening to port 8080 with plain HTTP. I will review the configurations
We know that Jenkins exposes its UI on port 8080/tcp. I would like to use the default port of 80 for HTTP traffic for this instance of Jenkins. So I’m going to change the listening port by modifying the configuration file at /etc/sysconfig/jenkins
$ sudo vi /etc/sysconfig/jenkins
Now let’s make sure that JENKINS_PORT=”8080″ is present in the file. This means that you will be able to access the Jenkins UI via HTTP at the port 8080. Restart Jenkins master just in case.
$ sudo systemctl restart jenkins
Opening a Port
To access the running instance of Jenkins master on your browser, the port 80/tcp has to be open on AWS side. Here is how you can do it.
Navigate to EC2 dashboard and click Security Groups under NETWORK & SECURITY on the left menu.
Click Create Security Group button and you will see a popup like the image below. Click Add Rule button and select Custom TCP on Type column. Enter 8080 in the Port Range column. Click Create button.
Now we are going to assign this security group to the instance we created previously. Navigate to Instances and make sure that the target instance is checked. Click Actions button and select Networking –> Change Security Groups.
Select the security group that was just created and click Assign Security Groups button.
This opens the port 8080 to the target instance. Let’s try to access it!
There are two ways to access it. If you navigate to the EC2 Instances page and select the target instance, you will see the detailed information about the instance. You can see the public DNS and its IP address so enter an URL like below.
http://[your public DNS]:8080
When it’s successful, you should see a UI asking you to unlock Jenkins.
I have already documented the way to configure Jenkins here in my previous post, so please refer to it from here on.
We have learned how to spin up a VM and actually install Jenkins master on it on AWS. There are a lot more to get to the point where Jenkins master may be secured and usable on AWS. The principle is pretty much the same as the one on Azure, such as enabling SSL and getting slaves communicate with it via the secured communication. I will talk more about it later in my blog.