Install Production Jenkins on CentOS 7 in 6 Steps

Chathura Siriwardhana
5 min readSep 22, 2019
Image Credits — Jenkins.io

Introduction

Jenkins is a free and open-source automation server written in Java. It helps to automate the non-human part of the software development process, with continuous integration and facilitating technical aspects of continuous delivery. Installation of Jenkins can be done via the default package manager or by downloading and running its web application archive (WAR) file. In this tutorial, I am teaching you to install Production Jenkins Server on CentOS 7.

Prerequisites

For this tutorial, I have used CentOS Linux release 7.6.1810. To this tutorial I used CentOS, but you can use the Ubuntu operating system as well.

See Choosing the Right Hardware for Masters for guidance in planning the capacity of a production Jenkins installation.

Step 1 — Install Java on the system

You can choose between Oracle Java or OpenJDK. I have gone with OpenJDK install via the package manager.

For CentOS

# sudo yum install java-1.8.0-openjdk -y

For Ubuntu

# sudo apt install openjdk-8-jdk

Step 2 — Configure Apache Tomcat

Go to the Apache Tomcat site and download the latest stable version. At the time I am writing this article the latest stable version was Apache Tomcat v9.0.26. You can download Tomcat 9.0.26 from here.

Create the directory /opt/jenkins. Download and extract Tomcat on this directory.

# sudo mkdir -p /opt/jenkins# sudo wget https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.26/bin/apache-tomcat-9.0.26.tar.gz -O /opt/jenkins/tompcat.tar.gz# sudo tar xvf /opt/jenkins/tompcat.tar.gz --directory /opt/jenkins/# sudo mv /opt/jenkins/apache-tomcat-9.0.26 /opt/jenkins/apache-tomcat\

Change the permission of the jenkins directory to centos user. You may not have a centos user. It’s always a good practice to change the permission to a non-root user.

# sudo chown -R centos:centos /opt/jenkins/

Remove all the directories in the Tomcat webapp directory.

# cd /opt/jenkins/apache-tomcat/webapps/# rm -rf *

Step 3 — Install Jenkins on CentOS

The big story, we are now going to download and install Jenkins on our system. Use the Jenkins official site to get the .war file. For a production environment, the best suite version is the Jenkins LTS version or the “Long-term Support”. By the time of this article, the latest stable version of Jenkins is the version 2.176.3.

# cd /opt/jenkins/apache-tomcat/webapps/
# wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war

Now, It's time to start the Tomcat server. You need to run the startup.sh script in the $TOMCAT_HOME/bin. According to this tutorial it is /opt/jenkins/apache-tomcat/bin

# cd /opt/jenkins/apache-tomcat/bin# ./startup.sh

You should see something similar to below If there is an error you did something wrong,

Using CATALINA_BASE:   /opt/jenkins/apache-tomcat
Using CATALINA_HOME: /opt/jenkins/apache-tomcat
Using CATALINA_TMPDIR: /opt/jenkins/apache-tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/jenkins/apache-tomcat/bin/bootstrap.jar:/opt/jenkins/apache-tomcat/bin/tomcat-juli.jar
Tomcat started.

Step 4 — Configure the CentOS firewalld

We need to open TCP port 8080 and 80 to access Jenkins from outside the machine.

# sudo firewall-cmd --permanent --add-port=8080/tcp# sudo firewall-cmd --permanent --add-service=http# sudo firewall-cmd --reload

Step 5 — Setting Up Jenkins on CentOS

Now you need to set up your new Jenkins installation. Open your favourite web browser and type the IP address or the domain name in the address bar. The address should be like http://your_ip_or_domain:8080/jenkins

Jenkins set up wizard first windo

The Jenkins installer creates a temporary password for you. You can find the temporary password by typing below command on the terminal,

# cat /home/centos/.jenkins/secrets/initialAdminPassword
4cf2398fbac841099b4dcbca68aebc14

Copy the password from your terminal, paste it into the Administrator password field and click Continue.

In the next screen, select Install suggested plugins box, wait for Jenkins to install plugins. Always you can add and remove plugins after the Jenkins installation.

Plugin inst

After the installation of the plugin finished, you will be prompted to set up the first admin user. Fill out all required information and click Save and Continue.

The next page will ask you to set the URL for your Jenkins instance. The field will be populated with an automatically generated URL. Confirm the URL by clicking on the Save and Finish button and the setup process will be completed.

Jenkins URL configuration Window

Click on the Start using Jenkins button and you will be redirected to the Jenkins dashboard logged in as the admin user you have created in one of the previous steps.

Step 6 — After Jenkins Install on CentOS Best Practices

On Jenkins document, it’s recommended to set up a reverse proxy to hide Jenkins and to use standard HTTP or HTTPSport. We can install apache httpd server or Nginx as a revers proxy. I use Nginx as the reverse proxy.

To install Nginx you can use the default package manager,

# sudo yum install -y epel-release
# sudo yum install nginx -y

Open the Nginx configuration file and add below lines between opening and closing curly bracket of “location /” directive.

proxy_set_header        Host $host:$server_port;proxy_set_header        X-Real-IP $remote_addr;proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header        X-Forwarded-Proto $scheme;proxy_read_timeout  90;proxy_pass          http://127.0.0.1:8080;proxy_redirect default;proxy_http_version 1.1;proxy_request_buffering off;add_header 'X-SSH-Endpoint' '192.168.118.21:50022' always;

Conclusion

In this tutorial, you have learned how to install and perform the initial configuration of Jenkins. You can now start exploring Jenkins features by visiting the official Jenkins documentation page.

--

--