jenkins
Devops, Linux

How to install Jenkins on CentOS

Jenkins is an open-source automation server that helps to automate different types of tasks such as building, testing, and deploying software ( wich is part of the CI/CD process). In this tutorial, we will learn how to install it on CentOS 7.9.

Prerequisites

Before we start installing ou automation server, we need to ensure that the following prerequisites are met :

-A CentOS 7.9 server with a non-root user with sudo privileges.

-Java 8 or later version should be installed on the server.

In this tutorial we will discuss about installing OpenJDK 11.

Installing OpenJDK 11 :

as root, run the command bellow to install java 11 :

[root@jenkins ~]# yum install java-11-openjdk

Once the installation is complete, check the version :

[root@jenkins ~]# java --version
openjdk 11.0.19 2023-04-18 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.19.0.7-1.el7_9) (build 11.0.19+7-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.19.0.7-1.el7_9) (build 11.0.19+7-LTS, mixed mode, sharing)

Now that’s our java is installed, let’s install automation server :

Install Jenkins

We need to set up the Jenkins repository. just follow the steps bellow :

Step 1: Run the following commande to download the repository file :

[root@jenkins ~]# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo

This command downloads the repository file and place it on /etc/yum.repos.d/. Let’s take a look on this file :

[root@jenkins ~]# cat /etc/yum.repos.d/jenkins.repo
[jenkins]
name=Jenkins-stable
baseurl=http://pkg.jenkins.io/redhat-stable
gpgcheck=1

Step 2: then we need to importe the key from jenkins :

[root@jenkins ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

Step 3: Now we can install jenkins :

[root@jenkins ~]# yum -y install jenkins
Running transaction
  Installing : jenkins-2.387.2-1.1.noarch                                                                                                                                                                     1/1
  Verifying  : jenkins-2.387.2-1.1.noarch                                                                                                                                                                     1/1
Installed:
  jenkins.noarch 0:2.387.2-1.1
Complete!

Check the the version :

[root@jenkins ~]# jenkins --version
2.387.2

Start and enable Jenkins service:

Now we need to start and enable the Jenkins service by running the following command :

[root@jenkins ~]# systemctl start jenkins
[root@jenkins ~]# systemctl enable jenkins
Created symlink from /etc/systemd/system/multi-user.target.wants/jenkins.service to /usr/lib/systemd/system/jenkins.service.

Check the status on the service :

[root@jenkins ~]# 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 Tue 2023-05-02 20:58:04 +01; 34s ago
 Main PID: 22890 (java)
   CGroup: /system.slice/jenkins.service
           └─22890 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=%C/jenkins/war --httpPort=8080

Adjust the Firewall

We need to open the 8080 port so you can access to Jenkinss on your web browser :

# firewall-cmd --permanent --zone=public --add-port=8080/tcp
# firewall-cmd --reload

Configuring Jenkins

Once Jenkins is installed, you can access it on your web browser by navigating to http://<your-server-IP>:8080 :

jenkins
Jenkins

On the login page, enter the initial admin password which can be found in the file :

/var/lib/jenkins/secrets/initialAdminPassword

Use cat commande to display your password :

[root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword

On the next screen, you will be asked whether you want to install the suggested plugins or to select specific plugins :

Choose to install suggested plugins and wait until the installation complete :

Jenkins

One the installation is complited, you will be asked to create the first admin user :

Fill out all required information and click on « Save and Continue ».

Click on « save and Finish ».

Finally, our automation is ready to use is ready to use :

That it,  you’ve successfully installed you automation server on your CentOS system.

To see How to reset Jenkins Admin Password click Here.

You might also like

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *