Installing Jenkins on Rocky Linux 9
DEV Community

Installing Jenkins on Rocky Linux 9

Jenkins is a popular open-source automation server for continuous integration and continuous deployment (CI/CD), letting teams build, test, and deploy software with a large ecosystem of plugins. This guide installs Jenkins on Rocky Linux 9, secures the web interface behind Nginx with a Let's Encrypt SSL certificate, tunes system limits for heavier workloads, and sets up automated backups. By the end, you'll have Jenkins running securely over HTTPS with a test job verified through both the dashboard and the Jenkins CLI.

Before you begin, you need access to a Rocky Linux 9 instance as a non-root sudo user, and a domain A record pointing to the instance's IP address (for example, example.com) configured with your DNS provider.

Install Java

Jenkins requires the Java Development Kit (JDK) to run.

  1. Update the package index:

    $ sudo dnf update -y
    
  2. Install OpenJDK 21 (or the latest version from the OpenJDK releases page):

    $ sudo dnf install -y java-21-openjdk
    
  3. Check for and switch away from an older default Java version:

    $ sudo alternatives --config java
    

    If multiple Java versions are installed, you'll see output like:

    There are two programs which provide 'java'.
    Selection Command
    -----------------------------------------------
    *+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.442.b06-2.el9.x86_64/jre/bin/java)
      2 java-21-openjdk.x86_64 (/usr/lib/jvm/java-21-openjdk-21.0.6.0.7-1.el9.x86_64/bin/java)
    Enter to keep the current selection[+], or type selection number:
    

    Type 2 to select OpenJDK 21.

  4. Verify the installation:

    $ java -version
    

    Output:

    openjdk 21.0.6 2025-01-21 LTS
    OpenJDK Runtime Environment (Red_Hat-21.0.6.0.7-1) (build 21.0.6+7-LTS)
    OpenJDK 64-Bit Server VM (Red_Hat-21.0.6.0.7-1) (build 21.0.6+7-LTS, mixed mode, sharing)
    

Install Jenkins

  1. Add the latest stable Jenkins repository to your DNF sources:

    $ sudo wget https://pkg.jenkins.io/redhat-stable/jenkins.repo -O /etc/yum.repos.d/jenkins.repo
    
  2. Import the GPG key for your version:

    $ sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
    
  3. Install Jenkins:

    $ sudo dnf install -y jenkins
    
  4. Start the Jenkins service:

    $ sudo systemctl start jenkins
    
  5. Enable Jenkins to start on boot:

    $ sudo systemctl enable jenkins
    
  6. Check its status:

    $ sudo systemctl status jenkins
    

    Output:

    โ— jenkins.service - Jenkins Continuous Integration Server
      Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: disabled)
      Active: active (running) since Sun 2025-02-23 10:45:53 UTC; 21s ago
    Main PID: 5166 (java)
        Tasks: 44 (limit: 11059)
        Memory: 407.4M
        CPU: 12.385s
      CGroup: /system.slice/jenkins.service
      โ””โ”€5166 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
    
    Feb 23 10:45:47 test-server jenkins[5166]: 69638179145e4a3fa6826e5fe6c427da
    Feb 23 10:45:47 test-server jenkins[5166]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword
    Feb 23 10:45:47 test-server jenkins[5166]: *************************************************************
    Feb 23 10:45:47 test-server jenkins[5166]: *************************************************************
    Feb 23 10:45:47 test-server jenkins[5166]: *************************************************************
    Feb 23 10:45:53 test-server jenkins[5166]: 2025-02-23 10:45:53.349+0000 [id = 32]INFO jenkins.InitReactorRunner$1#onAttained: Completed initiali>
    Feb 23 10:45:53 test-server jenkins[5166]: 2025-02-23 10:45:53.367+0000 [id = 24]INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up an>
    Feb 23 10:45:53 test-server systemd[1]: Started Jenkins Continuous Integration Server.
    Feb 23 10:45:55 test-server jenkins[5166]: 2025-02-23 10:45:55.036+0000 [id = 47]INFO h.m.DownloadService$Downloadable#load: Obtained the update>
    Feb 23 10:45:55 test-server jenkins[5166]: 2025-02-23 10:45:55.038+0000 [id = 47]INFO hudson.util.Retrier#start: Performed the action check upda>
    

Access the Jenkins Web Interface

  1. Allow the default Jenkins port 8080 through the firewall:

    $ sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
    
  2. Reload the firewall:

    $ sudo firewall-cmd --reload
    
  3. Get the initial administrator password:

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

    Copy the output.

  4. Open Jenkins in a browser using your domain name on port 8080: http://example.com:8080

  5. Paste the password into the Administrator Password field and click Continue.

  6. Select Install suggested Plugins to install the recommended Jenkins plugins.

  7. Fill in the details for your first Admin User and click Save and Continue.

  8. Confirm the Jenkins URL, which should match your domain name, then click Save and Finish.

  9. Click Start using Jenkins to open the Jenkins dashboard.

Secure Jenkins with Let's Encrypt SSL Certificates

  1. Install the Nginx web server:

    $ sudo dnf install nginx -y
    
  2. Install Certbot and its Nginx plugin:

    $ sudo dnf install -y certbot python3-certbot-nginx
    
  3. Allow HTTP traffic:

    $ sudo firewall-cmd --permanent --add-service=http
    
  4. Allow HTTPS traffic:

    $ sudo firewall-cmd --permanent --add-service=https
    
  5. Reload the firewall:

    $ sudo firewall-cmd --reload
    
  6. Request an SSL certificate:

    $ sudo certbot certonly --standalone -d example.com
    

    Certbot will prompt you in sequence: for an email address; to accept its terms of service; and, optionally, whether to share your email with the Electronic Frontier Foundation (you can decline with N). Your domain now has a valid certificate for TLS encryption.

  7. Enable and start Nginx:

    $ sudo systemctl enable --now nginx
    
  8. Allow Jenkins to communicate over the network via SELinux:

    $ sudo setsebool -P httpd_can_network_connect 1
    
  9. Open the Nginx configuration file:

    $ sudo nano /etc/nginx/conf.d/jenkins.conf
    

    Add the following configuration:

    server {
        listen 80;
        server_name example.com;
        return 301 https://$host$request_uri;
    }
    
    server {
        listen 443 ssl;
        server_name example.com;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    
        location / {
            proxy_pass http://127.0.0.1:8080;
            proxy_set_header Host $host;
            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_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Port $server_port;
    
            # WebSocket Support for Jenkins
            proxy_http_version 1.1;
            proxy_request_buffering off;
            proxy_buffering off;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
        }
    }
    

    Save and close the file.

    Note: don't add https:// or a trailing / to your domain in the server_name directive.

  10. Test the Nginx configuration:

    $ sudo nginx -t
    

    Output:

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
  11. Restart Nginx:

    $ sudo systemctl restart nginx
    
  12. Open your browser and go to: https://example.com

    Jenkins should now be accessible over HTTPS.

  13. Update the Jenkins URL to HTTPS. In the dashboard, go to Manage Jenkins > System, find the Jenkins Location section, change the URL from http://example.com:8080 to https://example.com/, and click Save.

  14. Restart Jenkins to apply the new URL:

    $ sudo systemctl restart jenkins
    

Optimize Jenkins Performance

Configure System Limits

  1. Open the limits configuration file:

    $ sudo nano /etc/security/limits.conf
    

    Add the following lines before the #End of file comment to raise the maximum open files Jenkins can use:

    jenkins soft nofile 65536
    jenkins hard nofile 65536
    

    Save and close the file.

  2. Restart Jenkins to apply the change:

    $ sudo systemctl restart jenkins
    
  3. Verify the new limit is applied:

    $ cat /proc/$(pgrep -u jenkins java)/limits | grep "open files"
    

    Output:

    Max open files  524288  524288  files
    

Implement a Backup Strategy

  1. Create a folder to store backups:

    $ mkdir ~/jenkins_backup
    
  2. Copy Jenkins data (configuration files, jobs, and user data) to the backup folder:

    $ sudo cp -r /var/lib/jenkins ~/jenkins_backup/
    
  3. Edit your cron jobs to schedule automatic daily backups:

    $ crontab -e
    
  4. Add the following line to run the backup every day at midnight:

    0 0 * * * sudo cp -r /var/lib/jenkins ~/jenkins_backup/
    

    Save and exit.

  5. Confirm the cron job was saved:

    $ crontab -l
    
  6. Check the cron service status:

    $ sudo systemctl status crond
    

    Output:

    โ— crond.service - Command Scheduler
      Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; preset: enabled)
      Active: active (running) since Sun 2025-02-23 10:43:02 UTC; 1h 18min ago
    Main PID: 1348 (crond)
        Tasks: 1 (limit: 11059)
        Memory: 1.2M
        CPU: 66ms
      CGroup: /system.slice/crond.service
      โ””โ”€1348 /usr/sbin/crond -n
    
    Feb 23 10:43:02 test-server crond[1348]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 33% if used.)
    Feb 23 10:43:02 test-server crond[1348]: (CRON) INFO (running with inotify support)
    Feb 23 11:01:01 test-server CROND[5547]: (root) CMD (run-parts /etc/cron.hourly)
    Feb 23 11:01:01 test-server run-parts[5550]: (/etc/cron.hourly) starting 0anacron
    Feb 23 11:01:01 test-server run-parts[5556]: (/etc/cron.hourly) finished 0anacron
    Feb 23 11:01:01 test-server CROND[5546]: (root) CMDEND (run-parts /etc/cron.hourly)
    Feb 23 12:01:01 test-server CROND[9621]: (root) CMD (run-parts /etc/cron.hourly)
    Feb 23 12:01:01 test-server run-parts[9624]: (/etc/cron.hourly) starting 0anacron
    Feb 23 12:01:01 test-server run-parts[9630]: (/etc/cron.hourly) finished 0anacron
    Feb 23 12:01:01 test-server CROND[9620]: (root) CMDEND (run-parts /etc/cron.hourly)
    

    If the status is active, the backup job will run as scheduled.

Access and Test Jenkins

Test via the Dashboard

  1. Open Jenkins in your browser and sign in to the dashboard.
  2. Click New Item, enter a job name (e.g., TestJob), select Freestyle Project, and click OK.
  3. Under Build Step, select Add build step > Execute shell and enter:
    $ echo "Hello, Jenkins!"
    
  4. Click Save, then Build Now to run the job.
  5. Open the build (e.g., #1) and click Console Output to view the logs - if you see the echoed message, the setup was successful.

Test Using the Command Line

  1. From the dashboard, click your username, then go to the Security tab.

  2. Under API Token, click Add New Token, name it, click Generate, and save the token securely.

  3. Download the Jenkins CLI jar file:

    $ wget https://example.com/jnlpJars/jenkins-cli.jar
    

    Replace example.com with your actual domain name.

  4. Move the jar file to a convenient location:

    $ mv jenkins-cli.jar ~/jenkins-cli.jar
    
  5. Check the connection:

    $ java -jar ~/jenkins-cli.jar -s https://example.com/ -auth your_username:your_api_token version
    

    Replace your_username and your_api_token with your Jenkins username and API token.

    Output:

    2.492.1
    
  6. Trigger the test job:

    $ java -jar ~/jenkins-cli.jar -s https://example.com/ -auth your_username:your_api_token build TestJob
    
  7. View the build console output:

    $ java -jar ~/jenkins-cli.jar -s https://example.com/ -auth your_username:your_api_token console TestJob
    

    Output:

    Running as SYSTEM
    Building in workspace /var/lib/jenkins/workspace/TestJob
    [TestJob] $ /bin/sh -xe /tmp/jenkins132166175190200986.sh
    + echo 'Hello, Jenkins!'
    Hello, Jenkins!
    Finished: SUCCESS
    

Next Steps

  • Connect Jenkins to your version control system and set up webhook-triggered builds.
  • Add build agents/nodes to distribute workloads across multiple machines.
  • Integrate Jenkins with your deployment pipeline (Docker, Kubernetes, or your cloud provider's CLI).
  • Explore additional plugins for testing, notifications, and artifact management.

For the full guide with additional tips, visit the original article on Vultr Docs.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.