Friday, December 27, 2024
Google search engine
HomeGuest BlogsHow To Install Jenkins on CentOS 8 / RHEL 8

How To Install Jenkins on CentOS 8 / RHEL 8

This article will guide you through the process of installing Jenkins on CentOS 8 / RHEL 8 server. Jenkins is an open source tool written in Java for automation and faster deployments. Jenkins is feature-rich and is vastly extendable through plugins.

After Jenkins installation, a guide on setting up Nginx as a reverse proxy to Jenkins server will be shared. We assume you have a ready RHEL / CentOS 8 server before you proceed. The process is identical to setup on RHEL / CentOS 7 system.

Minimum Hardware requirements:

  • 256 MB of RAM, 1 GB+ recommended
  • GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a Docker container)

Step 1: Install Java on RHEL / CentOS 8

Since Jenkins is written in Java, you need Java runtime environment setup on RHEL / CentOS 8.

sudo yum -y install java-11-openjdk-devel

Check Java version.

$ java -version
openjdk version "11.0.17" 2022-10-18 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.17.0.8-2.el8_6) (build 11.0.17+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.17.0.8-2.el8_6) (build 11.0.17+8-LTS, mixed mode, sharing)

Set Java environment.

sudo vi /etc/profile.d/java.sh

Add:

export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))
export PATH=$PATH:$JAVA_HOME/bin
export JRE_HOME=/usr/lib/jvm/jre
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

Source the file to start using it without logging out.

source /etc/profile.d/java.sh

Test

echo $JAVA_HOME
env

Step 2: Add Jenkins RPM repository

Start by importing the repository key from Jenkins

sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

After importing the key, add the repository to the system

sudo yum -y install wget
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo

Step 3: Install Jenkins on RHEL 8 / CentOS 8

Then install Jenkins package using yum:

sudo yum -y install jenkins

After installation, start and enable Jenkins service using:

sudo systemctl start jenkins
sudo systemctl enable jenkins

A check on status should return running state:

$ systemctl status jenkins
 jenkins.service - Jenkins Continuous Integration Server
   Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-10-30 10:51:31 EAT; 5s ago
 Main PID: 2426 (java)
    Tasks: 51 (limit: 49442)
   Memory: 2.2G
   CGroup: /system.slice/jenkins.service
           └─2426 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080

Oct 30 10:51:16 rocky8.mylab.io jenkins[2426]: Jenkins initial setup is required. An admin user has been created and a password generated.
Oct 30 10:51:16 rocky8.mylab.io jenkins[2426]: Please use the following password to proceed to installation:
Oct 30 10:51:16 rocky8.mylab.io jenkins[2426]: 00a531bbc7ee43db80edc20e4afeec65
Oct 30 10:51:16 rocky8.mylab.io jenkins[2426]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword
Oct 30 10:51:16 rocky8.mylab.io jenkins[2426]: *************************************************************
Oct 30 10:51:31 rocky8.mylab.io jenkins[2426]: 2022-10-30 07:51:31.563+0000 [id=28]        INFO        jenkins.InitReactorRunner$1#onAttained: Completed initialization
Oct 30 10:51:31 rocky8.mylab.io jenkins[2426]: 2022-10-30 07:51:31.641+0000 [id=22]        INFO        hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
Oct 30 10:51:31 rocky8.mylab.io systemd[1]: Started Jenkins Continuous Integration Server.
Oct 30 10:51:32 rocky8.mylab.io jenkins[2426]: 2022-10-30 07:51:32.124+0000 [id=46]        INFO        h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.M>
Oct 30 10:51:32 rocky8.mylab.io jenkins[2426]: 2022-10-30 07:51:32.124+0000 [id=46]        INFO        hudson.util.Retrier#start: Performed the action check updates server successfully at the attem>

Allow port 8080/tcp on the firewall.

sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

Step 4: Configure Jenkins on RHEL / CentOS 8

Browse to the URL http://[serverip|hostname]:8080 to access web installation wizard.

unlock jenkins centos7 min

When you first access a new Jenkins instance, you are asked to unlock it using an automatically generated password.

$ sudo  cat /var/lib/jenkins/secrets/initialAdminPassword
5e29f788df7748d2b5b3a62304aa0bc9

Copy-paste the automatically-generated alphanumeric password into the Administrator password field and click Continue.

jenkins install plugins min

Select Plugins to Install

install jenkins arch linux 02

Next is to create an admin user account used to manage the Jenkins server.

install jenkins centos7 set admin account min

Step 5: Configure Nginx and SSL (Optional)

It is recommended to access Jenkins Server behind a Proxy server secured with SSL certificate. Check below guide.

Step 6: Configure User Roles on Jenkins

By default, Jenkins user policy allows logged in users to access anything. This should not be the case and you need to set proper user policies. Check out our Jenkins policy and user management guide below.

Let other users Login with their credentials and assign them roles which define what they can do on Jenkins server.

Conclusion

Congratulations!!. You have successfully installed Jenkins on RHEL / CentOS 8. For more reading, check Official Documentation. We will be publishing more articles on Jenkins and CI/CD. Stay connected,

Other interesting article: How to Configure Jenkins FreeIPA LDAP Authentication

RELATED ARTICLES

Most Popular

Recent Comments