0

0

0

share


#jenkins#jenkins#jenkins#cicd
0 Reaksi

0 Komentar

Install Jenkins on CentOS

Profile
Danang Priabada

31 Agustus 2024

Install Jenkins on CentOS

In this guidance, you need internet access to install some prerequires.

Install Prerequisites

Before you start, ensure that you have Java installed, as Jenkins requires Java to run.

sudo yum install -y java-11-openjdk

Verify the installation:

java -version
openjdk version "11.0.20.1" 2023-08-24 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.20.1.1-2) (build 11.0.20.1+1-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.20.1.1-2) (build 11.0.20.1+1-LTS, mixed mode, sharing)
Download Jenkins WAR File:

Go to the Jenkins website to download the latest .war file :

cd /home/<user>/Downloads
wget https://get.jenkins.io/war-stable/latest/jenkins.war
--2024-08-30 19:53:05--  https://get.jenkins.io/war-stable/latest/jenkins.war
Resolving get.jenkins.io (get.jenkins.io)... 20.7.178.24, 2603:1030:408:5::15a
Connecting to get.jenkins.io (get.jenkins.io)|20.7.178.24|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://archives.jenkins.io/war-stable/latest/jenkins.war [following]
--2024-08-30 19:53:06--  https://archives.jenkins.io/war-stable/latest/jenkins.war
Resolving archives.jenkins.io (archives.jenkins.io)... 46.101.121.132, 2a03:b0c0:3:d0::9bc:d001
Connecting to archives.jenkins.io (archives.jenkins.io)|46.101.121.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 93287150 (89M)
Saving to: ‘jenkins.war’

jenkins.war                                                 100%[========================================================================================================================================>]  88.96M  2.14MB/s    in 28s

2024-08-30 19:53:35 (3.17 MB/s) - ‘jenkins.war’ saved [93287150/93287150]

Alternatively, you can download it directly using a browser from Jenkins’ official site. https://www.jenkins.io/download/

Create a Directory for Jenkins:

Create a directory where Jenkins will run from:

sudo mkdir /opt/jenkins
sudo mv jenkins.war /opt/jenkins/

Adjust the access

sudo chown -R root:root /opt/jenkins
sudo chmod -R 755 /opt/jenkins

Create a Systemd Service File To manage Jenkins with systemctl, create a systemd service file. Create the Service File: Create a file named jenkins.service in the /etc/systemd/system/ directory

sudo nano /etc/systemd/system/jenkins.service

Add the Following Content: If you want Jenkins to use a different port, modify the ExecStart line in the /etc/systemd/system/jenkins.service file to include the --httpPort option:

[Unit]
Description=Jenkins Daemon
After=network.target
Wants=network-online.target

[Service]
User=root
Group=root
WorkingDirectory=/opt/jenkins
ExecStart=/usr/bin/java -Djenkins.install.runSetupWizard=false -jar /opt/jenkins/jenkins.war --httpPort=9090
ExecStop=/bin/kill -TERM $MAINPID
Restart=always
RestartSec=10
TimeoutStartSec=180
TimeoutStopSec=180
SuccessExitStatus=143
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=jenkins

[Install]
WantedBy=multi-user.target

Reload Systemd and Start Jenkins

sudo systemctl daemon-reload
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl restart jenkins
Check the Status:

Verify that Jenkins is running

sudo systemctl status jenkins
[root@localhost jenkins]# sudo systemctl status jenkins
● jenkins.service - Jenkins Daemon
     Loaded: loaded (/etc/systemd/system/jenkins.service; enabled; preset: disabled)
     Active: active (running) since Fri 2024-08-30 20:32:15 WIB; 10min ago
   Main PID: 39739 (java)
      Tasks: 49 (limit: 21491)
     Memory: 379.0M
        CPU: 46.475s
     CGroup: /system.slice/jenkins.service
             └─39739 /usr/bin/java -Djenkins.install.runSetupWizard=false -jar /opt/jenkins/jenkins.war --httpPort=9090

Aug 30 20:32:27 localhost.localdomain jenkins[39739]: WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
Aug 30 20:32:27 localhost.localdomain jenkins[39739]: WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
Aug 30 20:32:27 localhost.localdomain jenkins[39739]: WARNING: All illegal access operations will be denied in a future release
Aug 30 20:32:28 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:28.533+0000 [id=36]        INFO        h.p.b.g.GlobalTimeOutConfiguration#load: global timeout not set
Aug 30 20:32:29 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:29.941+0000 [id=36]        INFO        jenkins.InitReactorRunner$1#onAttained: System config loaded
Aug 30 20:32:29 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:29.942+0000 [id=36]        INFO        jenkins.InitReactorRunner$1#onAttained: System config adapted
Aug 30 20:32:30 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:30.010+0000 [id=32]        INFO        jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
Aug 30 20:32:30 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:30.013+0000 [id=32]        INFO        jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
Aug 30 20:32:30 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:30.117+0000 [id=36]        INFO        jenkins.InitReactorRunner$1#onAttained: Completed initialization
Aug 30 20:32:30 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:30.167+0000 [id=23]        INFO        hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running

Jenkins Logs: To monitor Jenkins logs, use

sudo journalctl -u jenkins -f
[root@localhost jenkins]# sudo journalctl -u jenkins -f
Aug 30 20:32:27 localhost.localdomain jenkins[39739]: WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
Aug 30 20:32:27 localhost.localdomain jenkins[39739]: WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
Aug 30 20:32:27 localhost.localdomain jenkins[39739]: WARNING: All illegal access operations will be denied in a future release
Aug 30 20:32:28 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:28.533+0000 [id=36]        INFO        h.p.b.g.GlobalTimeOutConfiguration#load: global timeout not set
Aug 30 20:32:29 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:29.941+0000 [id=36]        INFO        jenkins.InitReactorRunner$1#onAttained: System config loaded
Aug 30 20:32:29 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:29.942+0000 [id=36]        INFO        jenkins.InitReactorRunner$1#onAttained: System config adapted
Aug 30 20:32:30 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:30.010+0000 [id=32]        INFO        jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
Aug 30 20:32:30 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:30.013+0000 [id=32]        INFO        jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
Aug 30 20:32:30 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:30.117+0000 [id=36]        INFO        jenkins.InitReactorRunner$1#onAttained: Completed initialization
Aug 30 20:32:30 localhost.localdomain jenkins[39739]: 2024-08-30 13:32:30.167+0000 [id=23]        INFO        hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running

Check jenkins port already LISTEN

netstat -an | grep :9090
tcp6       0      0 :::9090                 :::*                    LISTEN
Access Jenkins

Unlock Jenkins: http://you-ip-address:9090/

When you first access Jenkins, you’ll be asked for an unlock key. This key is stored in the file /root/.jenkins/secrets/initialAdminPassword.

Retrieve the key:

sudo cat /root/.jenkins/secrets/initialAdminPassword
Image
Image
Configure Firewall (If Necessary)

If your server has a firewall enabled, open port 9090:

sudo firewall-cmd --permanent --add-port=9090/tcp
sudo firewall-cmd --reload
Secure Connection

Now you can Set Up Jenkins with HTTPS using NGINX to secure and ensure that all traffic to your Jenkins server is encrypted, providing a secure connection for your CI/CD pipelines.

0

0

0

share