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
- AWS Account (Create if you don’t have one).
- 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?
- Download Jenkins and Apache Tomcat Package.
- Install Java and initialize Apache Tomcat with Jenkins.
- 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 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
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
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
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 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
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
Check the java version to make sure that the Java has been installed.
java -version
ls -lt
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
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/
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
Verify that the Apache Tomcat has started successfully and there are no errors in logs.
tail -100f ../logs/catalina.out
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
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.
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.
Customize Jenkins and install suggested plugins. This will take some time.
You can create a new Admin user or skip the user creation and proceed with the current Admin user and Password.
Keep the URL as is and click on "Save and Finish".
Now Jenkins is ready to use.
Here you see the Jenkins 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.