How to install Jenkins on Linux
Table of Contents
___________________________________________________________________________________________________
Step 1: Add Jenkins repo
Step 2: Install Java
Step 3: Install Jenkins packages
Step 4: Start Jenkins service
Step 5: Allow Jenkins port in firewall
Step 6: Step Jenkins portal
Optional – Execute if requires
Step 7: Change the shell for jenkins user to /bin/bash
Step 8: Add user jenkins to the sudoers file without requiring a password
Step 9: Enable password authentication in sshd_config
Step 10: Restart sshd
___________________________________________________________________________________________________
[root@rac1 ~]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo --2023-09-09 12:42:43-- https://pkg.jenkins.io/redhat-stable/jenkins.repo Resolving pkg.jenkins.io (pkg.jenkins.io)... 199.232.46.133, 2a04:4e42:48::645 Connecting to pkg.jenkins.io (pkg.jenkins.io)|199.232.46.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 85 Saving to: β/etc/yum.repos.d/jenkins.repoβ /etc/yum.repos.d/jenkins.repo 100%[========================================>] 85 --.-KB/s in 0s 2023-09-09 12:42:45 (569 KB/s) - β/etc/yum.repos.d/jenkins.repoβ saved [85/85] [root@rac1 ~]# [root@rac1 ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key [root@rac1 ~]#
[root@rac1 ~]# yum install fontconfig java-11-openjdk App Stream Repo 2.2 MB/s | 2.8 kB 00:00 BaseOS Repo 2.3 MB/s | 2.3 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 5.8 kB/s | 8.5 kB 00:01 Extra Packages for Enterprise Linux 8 - x86_64 175 kB/s | 16 MB 01:32 Jenkins-stable 21 kB/s | 27 kB 00:01 Oracle Linux 8 BaseOS Latest (x86_64) 61 kB/s | 3.6 kB 00:00 Oracle Linux 8 BaseOS Latest (x86_64) 25 MB/s | 62 MB 00:02 Oracle Linux 8 Application Stream (x86_64) 71 kB/s | 3.9 kB 00:00 Oracle Linux 8 Application Stream (x86_64) 26 MB/s | 48 MB 00:01 Latest Unbreakable Enterprise Kernel Release 6 for Oracle Linux 8 (x86_64) 76 kB/s | 3.0 kB 00:00 Latest Unbreakable Enterprise Kernel Release 6 for Oracle Linux 8 (x86_64) 25 MB/s | 75 MB 00:02 Package fontconfig-2.13.1-4.el8.x86_64 is already installed. Dependencies resolved. =========================================================================================================== Package Architecture Version Repository Size =========================================================================================================== Installing: java-11-openjdk x86_64 1:11.0.20.0.8-3.0.1.el8 ol8_appstream 473 k Installing dependencies: copy-jdk-configs noarch 4.0-2.el8 AppStream 30 k java-11-openjdk-headless x86_64 1:11.0.20.0.8-3.0.1.el8 ol8_appstream 42 M javapackages-filesystem noarch 5.3.0-1.module+el8+5136+7ff78f74 AppStream 30 k lksctp-tools x86_64 1.0.18-3.el8 BaseOS 100 k ttmkfdir x86_64 3.0.9-54.el8 AppStream 62 k tzdata-java noarch 2023c-1.el8 ol8_appstream 186 k xorg-x11-fonts-Type1 noarch 7.5-19.el8 AppStream 522 k Enabling module streams: javapackages-runtime 201801 Transaction Summary =========================================================================================================== Install 8 Packages Total size: 43 M Total download size: 42 M Installed size: 180 M Is this ok [y/N]: y Downloading Packages: (1/3): tzdata-java-2023c-1.el8.noarch.rpm 1.5 MB/s | 186 kB 00:00 (2/3): java-11-openjdk-11.0.20.0.8-3.0.1.el8.x86_64.rpm 218 kB/s | 473 kB 00:02 (3/3): java-11-openjdk-headless-11.0.20.0.8-3.0.1.el8.x86_64.rpm 14 MB/s | 42 MB 00:02 ------------------------------------------------------------------------------------------------------------------- Total 14 MB/s | 42 MB 00:02 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Running scriptlet: copy-jdk-configs-4.0-2.el8.noarch 1/1 Running scriptlet: java-11-openjdk-headless-1:11.0.20.0.8-3.0.1.el8.x86_64 1/1 Preparing : 1/1 Installing : tzdata-java-2023c-1.el8.noarch 1/8 Installing : lksctp-tools-1.0.18-3.el8.x86_64 2/8 Running scriptlet: lksctp-tools-1.0.18-3.el8.x86_64 2/8 Installing : ttmkfdir-3.0.9-54.el8.x86_64 3/8 Installing : xorg-x11-fonts-Type1-7.5-19.el8.noarch 4/8 Running scriptlet: xorg-x11-fonts-Type1-7.5-19.el8.noarch 4/8 Installing : javapackages-filesystem-5.3.0-1.module+el8+5136+7ff78f74.noarch 5/8 Installing : copy-jdk-configs-4.0-2.el8.noarch 6/8 Installing : java-11-openjdk-headless-1:11.0.20.0.8-3.0.1.el8.x86_64 7/8 Running scriptlet: java-11-openjdk-headless-1:11.0.20.0.8-3.0.1.el8.x86_64 7/8 Installing : java-11-openjdk-1:11.0.20.0.8-3.0.1.el8.x86_64 8/8 Running scriptlet: java-11-openjdk-1:11.0.20.0.8-3.0.1.el8.x86_64 8/8 Running scriptlet: copy-jdk-configs-4.0-2.el8.noarch 8/8 Running scriptlet: java-11-openjdk-headless-1:11.0.20.0.8-3.0.1.el8.x86_64 8/8 Running scriptlet: java-11-openjdk-1:11.0.20.0.8-3.0.1.el8.x86_64 8/8 Verifying : copy-jdk-configs-4.0-2.el8.noarch 1/8 Verifying : javapackages-filesystem-5.3.0-1.module+el8+5136+7ff78f74.noarch 2/8 Verifying : ttmkfdir-3.0.9-54.el8.x86_64 3/8 Verifying : xorg-x11-fonts-Type1-7.5-19.el8.noarch 4/8 Verifying : lksctp-tools-1.0.18-3.el8.x86_64 5/8 Verifying : java-11-openjdk-1:11.0.20.0.8-3.0.1.el8.x86_64 6/8 Verifying : java-11-openjdk-headless-1:11.0.20.0.8-3.0.1.el8.x86_64 7/8 Verifying : tzdata-java-2023c-1.el8.noarch 8/8 Installed products updated. Installed: copy-jdk-configs-4.0-2.el8.noarch java-11-openjdk-1:11.0.20.0.8-3.0.1.el8.x86_64 java-11-openjdk-headless-1:11.0.20.0.8-3.0.1.el8.x86_64 javapackages-filesystem-5.3.0-1.module+el8+5136+7ff78f74.noarch lksctp-tools-1.0.18-3.el8.x86_64 ttmkfdir-3.0.9-54.el8.x86_64 tzdata-java-2023c-1.el8.noarch xorg-x11-fonts-Type1-7.5-19.el8.noarch Complete! [root@rac1 ~]# [root@rac1 ~]# java -version openjdk version "11.0.20" 2023-07-18 LTS OpenJDK Runtime Environment (Red_Hat-11.0.20.0.8-2.0.1) (build 11.0.20+8-LTS) OpenJDK 64-Bit Server VM (Red_Hat-11.0.20.0.8-2.0.1) (build 11.0.20+8-LTS, mixed mode, sharing) [root@rac1 ~]#
Step 3: Install Jenkins packages
[root@rac1 ~]# yum install jenkins Last metadata expiration check: 0:02:19 ago on Sat 09 Sep 2023 12:47:32 PM UTC. Dependencies resolved. ==================================================================================================================== Package Architecture Version Repository Size ==================================================================================================================== Installing: jenkins noarch 2.414.1-1.1 jenkins 85 M Transaction Summary ==================================================================================================================== Install 1 Package Total download size: 85 M Installed size: 85 M Is this ok [y/N]: y Downloading Packages: jenkins-2.414.1-1.1.noarch.rpm 14 MB/s | 85 MB 00:06 ---------------------------------------------------------------------------------------- Total 14 MB/s | 85 MB 00:06 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: jenkins-2.414.1-1.1.noarch 1/1 Installing : jenkins-2.414.1-1.1.noarch 1/1 Running scriptlet: jenkins-2.414.1-1.1.noarch 1/1 Verifying : jenkins-2.414.1-1.1.noarch 1/1 Installed products updated. Installed: jenkins-2.414.1-1.1.noarch Complete! [root@rac1 ~]#
[root@rac1 ~]# systemctl enable jenkins Synchronizing state of jenkins.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install enable jenkins Created symlink /etc/systemd/system/multi-user.target.wants/jenkins.service β /usr/lib/systemd/system/jenkins.service. [root@rac1 ~]# [root@rac1 ~]# systemctl status jenkins β jenkins.service - Jenkins Continuous Integration Server Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; vendor preset: disabled) Active: inactive (dead) [root@rac1 ~]# [root@rac1 ~]# systemctl start jenkins [root@rac1 ~]# [root@rac1 ~]# 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 Sat 2023-09-09 12:59:49 UTC; 10s ago Main PID: 30815 (java) Tasks: 48 (limit: 48416) Memory: 2.1G CGroup: /system.slice/jenkins.service ββ30815 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080 Sep 09 12:58:35 rac1.rajasekhar.com jenkins[30815]: Jenkins initial setup is required. An admin user has been created and a password generated. Sep 09 12:58:35 rac1.rajasekhar.com jenkins[30815]: Please use the following password to proceed to installation: Sep 09 12:58:35 rac1.rajasekhar.com jenkins[30815]: f08c2d6392b246ffa83291fd08374ee8 Sep 09 12:58:35 rac1.rajasekhar.com jenkins[30815]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword Sep 09 12:58:35 rac1.rajasekhar.com jenkins[30815]: ************************************************************* Sep 09 12:59:49 rac1.rajasekhar.com jenkins[30815]: 2023-09-09 12:59:49.892+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization Sep 09 12:59:49 rac1.rajasekhar.com jenkins[30815]: 2023-09-09 12:59:49.913+0000 [id=22] INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running Sep 09 12:59:49 rac1.rajasekhar.com systemd[1]: Started Jenkins Continuous Integration Server. Sep 09 12:59:51 rac1.rajasekhar.com jenkins[30815]: 2023-09-09 12:59:51.176+0000 [id=46] INFO h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller Sep 09 12:59:51 rac1.rajasekhar.com jenkins[30815]: 2023-09-09 12:59:51.178+0000 [id=46] INFO hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1 [root@rac1 ~]#
Step 5: Allow Jenkins port in firewall
[root@rac1 ~]# systemctl status firewalld β firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: active (running) since Sat 2023-09-09 14:02:59 UTC; 2s ago Docs: man:firewalld(1) Main PID: 31925 (firewalld) Tasks: 2 (limit: 48416) Memory: 23.8M CGroup: /system.slice/firewalld.service ββ31925 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid Sep 09 14:02:58 rac1.rajasekhar.com systemd[1]: Starting firewalld - dynamic firewall daemon... Sep 09 14:02:59 rac1.rajasekhar.com systemd[1]: Started firewalld - dynamic firewall daemon. Sep 09 14:02:59 rac1.rajasekhar.com firewalld[31925]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now. [root@rac1 ~]# [root@rac1 ~]# firewall-cmd --permanent --add-port=8080/tcp success [root@rac1 ~]# [root@rac1 ~]# firewall-cmd --reload success [root@rac1 ~]# [root@rac1 ~]# firewall-cmd --list-all | grep -i 8080 ports: 8080/tcp [root@rac1 ~]#
Optional – Execute if requires
Step 7: Change the shell for jenkins user to /bin/bash
[root@rac1 ~]# cat /etc/passwd | grep -i jenkins jenkins:x:973:973:Jenkins Automation Server:/var/lib/jenkins:/bin/false [root@rac1 ~]# [root@rac1 ~]# usermod -s /bin/bash jenkins [root@rac1 ~]# [root@rac1 ~]# cat /etc/passwd | grep -i jenkins jenkins:x:973:973:Jenkins Automation Server:/var/lib/jenkins:/bin/bash [root@rac1 ~]#
Step 8: Add user jenkins to the sudoers file without requiring a password
[root@rac1 ~]# cat /etc/sudoers | grep -i jenkins <--- no output [root@rac1 ~]# [root@rac1 ~]# echo "jenkins ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers jenkins ALL=(ALL) NOPASSWD: ALL [root@rac1 ~]# [root@rac1 ~]# cat /etc/sudoers | grep -i jenkins jenkins ALL=(ALL) NOPASSWD: ALL [root@rac1 ~]#
Step 9: Enable password authentication in sshd_config
[root@rac1 ~]# grep -E '^\s*#?\s*PasswordAuthentication' /etc/ssh/sshd_config | head -n 1 #PasswordAuthentication no [root@rac1 ~]# [root@rac1 ~]# sed -i 's/^\s*#*\s*PasswordAuthentication\s\+no/PasswordAuthentication yes/' /etc/ssh/sshd_config [root@rac1 ~]# [root@rac1 ~]# grep -E '^\s*#?\s*PasswordAuthentication' /etc/ssh/sshd_config | head -n 1 PasswordAuthentication yes [root@rac1 ~]#
[root@rac1 ~]# systemctl restart sshd [root@rac1 ~]# [root@rac1 ~]# systemctl status sshd β sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2023-09-09 15:39:50 UTC; 4min 50s ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 33235 (sshd) Tasks: 1 (limit: 48416) Memory: 1.1M CGroup: /system.slice/sshd.service ββ33235 /usr/sbin/sshd -D -u0 -oCiphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc,aes128-gcm@openssh.com,aes128-ctr,aes128-cbc -oMACs=hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,um> Sep 09 15:39:49 rac1.rajasekhar.com systemd[1]: Starting OpenSSH server daemon... Sep 09 15:39:50 rac1.rajasekhar.com sshd[33235]: Server listening on 0.0.0.0 port 22. Sep 09 15:39:50 rac1.rajasekhar.com sshd[33235]: Server listening on :: port 22. Sep 09 15:39:50 rac1.rajasekhar.com systemd[1]: Started OpenSSH server daemon. [root@rac1 ~]#