How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance

Jenkins is an open-source Continuous Integration and Continuous Deployment tool. It is an automation tool that helps build, test and deploy software reliably. It is written in Java and comes with hundreds of plugins. Jenkins also supports the distribution of work across multiple servers. It is very easy to configure Jenkins and get started with it. In this article, we will install Jenkins using the .war file in Apache Tomcat. We will use AWS EC2 Ubuntu 18.04 server to perform this activity. You can even use a Virtual Machine on your local machine or remote server with Ubuntu 18.04 on it.

Pre-requisites

  1. AWS Account (Create if you don’t have one).
  2. An EC2 Instance(Click here to learn to create an EC2 Instance) or a VM with at least 256 MB of RAM and 1 GB of drive space.

What will we do?

  1. Download Jenkins and Apache Tomcat Package.
  2. Install Java and initialize Apache Tomcat with Jenkins.
  3. Initial Setup of Jenkins.

Download Jenkins and Apache Tomcat Package

Before we get started with the installation, let's check the OS version and see if Java is available on the server using the following commands.

cat /etc/issue

java

Check OS version

Check the current user you are logged in with and change to "root" user.

whoami

sudo -i

whoami

Create a  new directory in /opt/ where we will download Jenkins and Apache Tomcat packages.

cd /opt/

mkdir jenkins

cd jenkins/

pwd

Create a folder

Go to Jenkins download page and get the URL of the war file to download the Jenkins package

https://www.jenkins.io/download/

In this case, the following is the URL to download the war file of Jenkins.

https://get.jenkins.io/war-stable/2.263.4/jenkins.war

Get jenkins.war file download URL

Now, you can use the "wget" command to download the war file on your server.

wget https://get.jenkins.io/war-stable/2.263.4/jenkins.war

ls -l

Download jenkins.war file on the server

Go to the Apache tomcat website to download the package. We will use Apache Tomcat 9 package.

https://tomcat.apache.org/download-90.cgi

Get Apache-Tomcat package download URL

Get the URL of the package and download it on the server using "get". 

wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.43/bin/apache-tomcat-9.0.43.tar.gz

ls -lt

Download Apache-Tomcat package

Install Java and initialize Apache Tomcat with Jenkins

Apache Tomcat requires Java to run, so before we proceed we need to install java on the server.

Use the following command to update the system.

apt update

Once the system is updated, install Java 8 on Ubuntu using the following command.

apt install openjdk-8-jdk

Install OpenJava 8

Check the java version to make sure that the Java has been installed.

java -version

ls -lt

Check Java version

Now, we are ready to use Apache Tomcat. Extract the tar file we have downloaded in the previous step.

tar -zxvf apache-tomcat-9.0.43.tar.gz

ls -lt

Extract Apache-Tomcat package

Move/Copy Jenkins war file to webapp directory of Apache Tomcat.

mv jenkins.war apache-tomcat-9.0.43/webapps/

ls -lt

ls -lt apache-tomcat-9.0.43/webapps/

Move jenkins.war to webapp directory

We are now ready to start Apache Tomcat. Before that, let's see if 8080 used by Apache Tomcat is free or not.

cd apache-tomcat-9.0.43/bin/

netstat -tulpn | grep 8080

If no other service is running on 8080, we are ready to start Apache Tomcat. 

Use the following command to start the service.

./startup.sh

Check if the service has started.

netstat -tulpn | grep 8080

Start Apache-Tomcat

Verify that the Apache Tomcat has started successfully and there are no errors in logs.

tail -100f ../logs/catalina.out

Check logs of Apache-Tomcat

We need to do the initial setup of Jenkins, to do so we need to use the password available in "initialAdminPassword". 

Get the password that will be required to login into Jenkins. You can see the "initialAdminPassword" file path in the Apache Tomcat logs.

cat  /root/.jenkins/secrets/initialAdminPassword

You can also check if the Apache Process is running, use the following command.

ps -ef| grep apache

Fetch Jenkins AdminPassword

To access Jenkins on Port 8080, we need to make sure that the incoming connection on the port is allowed in the Security group of the EC2 instance.

Allow connection on Port 8080 in the security-group on the EC2 instance

Get the public IP of the EC2 instance.

Get the public IP of the EC2 instance

Initial Setup of Jenkins

Access Jenkins on http://<public-ip>:port/jenkins 

http://52.87.233.129:8080/jenkins

Insert the password fetched from the "initialAdminPassword" file.

Access and Unlock Jenkins

Customize Jenkins and install suggested plugins. This will take some time.

Install suggested plugins

You can create a new Admin user or skip the user creation and proceed with the current Admin user and Password. 

Proceed with Admin user

Keep the URL as is and click on "Save and Finish".

Keep default Jenkins URL

Now Jenkins is ready to use.

Jenkins is ready

Here you see the Jenkins Dashboard.

Jenkins main dashboard

Conclusion

In this article, we saw the steps to install Jenkins using the .war file. We carried out this activity on the AWS EC2 Ubuntu 18.04 Server. We installed Java which is required by Jenkins and used Apache Tomcat to deploy the jenkins.war file. We logged in using the Admin user and did the initial setup of Jenkins using the suggested plugins.

Share this page:

0 Comment(s)