DEV Community

Janak Shrestha
Janak Shrestha

Posted on

Day 75: Jenkins Slave Nodes

The Nautilus DevOps team has installed and configured new Jenkins server in Stratos DC which they will use for CI/CD and for some automation tasks. There is a requirement to add all app servers as slave nodes in Jenkins so that they can perform tasks on these servers using Jenkins. Find below more details and accomplish the task accordingly.

Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and password Adm!n321.

  1. Add all app servers as SSH build agent/slave nodes in Jenkins. Slave node name for app server 1, app server 2 and app server 3 must be App_server_1, App_server_2, App_server_3 respectively.

  2. Add labels as below:

App_server_1 : stapp01

App_server_2 : stapp02

App_server_3 : stapp03

  1. Remote root directory for App_server_1 must be /home/tony/jenkins, for App_server_2 must be /home/steve/jenkins and for App_server_3 must be /home/banner/jenkins.

  2. Make sure slave nodes are online and working properly.

Note:

  1. You might need to install some plugins and restart Jenkins service. So, we recommend clicking on Restart Jenkins when installation is complete and no jobs are running on plugin installation/update page i.e update centre. Also, Jenkins UI sometimes gets stuck when Jenkins service restarts in the back end. In this case, please make sure to refresh the UI page.
  2. For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.

Understanding Jenkins Master-Agent Architecture

Jenkins uses a master-agent architecture:

Component Role
Master (Controller) Schedules jobs, manages configuration, serves the UI
Agent (Slave/Node) Executes build tasks assigned by the master

Why Use Slave Nodes?

  • Distributed Builds: Run multiple jobs in parallel
  • Server-Specific Tasks: Run jobs on specific servers
  • Load Distribution: Reduce load on the master
  • Environment Isolation: Different environments for different builds
  • Scalability: Add more agents as needed

Task Requirements

Server Node Name Label Remote Root Directory
App Server 1 App_server_1 stapp01 /home/tony/jenkins
App Server 2 App_server_2 stapp02 /home/steve/jenkins
App Server 3 App_server_3 stapp03 /home/banner/jenkins

Step-by-Step Implementation

Step 1: Access Jenkins UI

  1. Click the Jenkins button on the top bar
  2. Login with:
    • Username: admin
    • Password: Adm!n321

Step 2: Install SSH Build Agents Plugin

  1. Navigate to Manage JenkinsPlugins
  2. Click Available plugins
  3. Search for SSH Build Agents
  4. Install the plugin and restart Jenkins

Note: Select Restart Jenkins when installation is complete and no jobs are running.

Step 3: Generate SSH Keys on Jenkins Server

The Jenkins job runs as the jenkins user, so SSH keys must be generated for this user.

# SSH to Jenkins server
ssh jenkins@jenkins
# Password: j@rv!s

# Generate SSH key
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa

# View the private key (needed for Jenkins credentials)
cat ~/.ssh/id_rsa
Enter fullscreen mode Exit fullscreen mode

Output:

Generating public/private rsa key pair.
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa
Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

Step 4: Copy SSH Keys to All App Servers

# Copy public key to App Server 1
ssh-copy-id -o StrictHostKeyChecking=no tony@stapp01
# Password: Ir0nM@n

# Copy public key to App Server 2
ssh-copy-id -o StrictHostKeyChecking=no steve@stapp02
# Password: Am3ric@

# Copy public key to App Server 3
ssh-copy-id -o StrictHostKeyChecking=no banner@stapp03
# Password: BigGr33n

# Verify passwordless access
ssh -o StrictHostKeyChecking=no tony@stapp01 hostname
ssh -o StrictHostKeyChecking=no steve@stapp02 hostname
ssh -o StrictHostKeyChecking=no banner@stapp03 hostname
Enter fullscreen mode Exit fullscreen mode

Output:

stapp01
stapp02
stapp03
Enter fullscreen mode Exit fullscreen mode

Step 5: Install Java 21 on All App Servers

Jenkins agents require Java 17 or higher. Java 11 will cause an UnsupportedClassVersionError.

# Install Java 21 on all servers
ssh tony@stapp01 "sudo yum install -y java-21-openjdk"
ssh steve@stapp02 "sudo yum install -y java-21-openjdk"
ssh banner@stapp03 "sudo yum install -y java-21-openjdk"
Enter fullscreen mode Exit fullscreen mode

Step 6: Register and Set Java 21 as Default

After installing Java 21, you need to register it as an alternative and set it as default.

# Register Java 21 as an alternative
ssh tony@stapp01 "echo 'Ir0nM@n' | sudo -S alternatives --install /usr/bin/java java /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java 2000"
ssh steve@stapp02 "echo 'Am3ric@' | sudo -S alternatives --install /usr/bin/java java /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java 2000"
ssh banner@stapp03 "echo 'BigGr33n' | sudo -S alternatives --install /usr/bin/java java /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java 2000"

# Set Java 21 as default
ssh tony@stapp01 "echo 'Ir0nM@n' | sudo -S alternatives --set java /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java"
ssh steve@stapp02 "echo 'Am3ric@' | sudo -S alternatives --set java /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java"
ssh banner@stapp03 "echo 'BigGr33n' | sudo -S alternatives --set java /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java"
Enter fullscreen mode Exit fullscreen mode

Verify:

ssh tony@stapp01 "java -version"
ssh steve@stapp02 "java -version"
ssh banner@stapp03 "java -version"
Enter fullscreen mode Exit fullscreen mode

Output:

openjdk version "21.0.12.1" 2026-08-18 LTS
Enter fullscreen mode Exit fullscreen mode

Step 7: Create Remote Root Directories

ssh -o StrictHostKeyChecking=no tony@stapp01 "mkdir -p /home/tony/jenkins"
ssh -o StrictHostKeyChecking=no steve@stapp02 "mkdir -p /home/steve/jenkins"
ssh -o StrictHostKeyChecking=no banner@stapp03 "mkdir -p /home/banner/jenkins"
Enter fullscreen mode Exit fullscreen mode

Step 8: Get IP Addresses for Hostname Resolution

ssh tony@stapp01 "hostname -I"
ssh steve@stapp02 "hostname -I"
ssh banner@stapp03 "hostname -I"
Enter fullscreen mode Exit fullscreen mode

Output:

10.244.81.4
10.244.189.193
10.244.195.103
Enter fullscreen mode Exit fullscreen mode

Step 9: Add SSH Credentials in Jenkins

  1. Go to Manage JenkinsCredentialsSystemGlobal credentials
  2. Click Add Credentials for each server:

App Server 1 Credentials:

  • Kind: SSH Username with private key
  • Scope: Global
  • ID: stapp01-credentials
  • Username: tony
  • Private Key: Enter directly (paste the private key from ~/.ssh/id_rsa)
  • Click OK

App Server 2 Credentials:

  • Kind: SSH Username with private key
  • ID: stapp02-credentials
  • Username: steve
  • Private Key: Enter directly
  • Click OK

App Server 3 Credentials:

  • Kind: SSH Username with private key
  • ID: stapp03-credentials
  • Username: banner
  • Private Key: Enter directly
  • Click OK

Step 10: Add Slave Nodes in Jenkins

Add App_server_1 Node:

  1. Manage JenkinsNodesNew Node
  2. Enter name: App_server_1
  3. Select Permanent AgentOK
  4. Configure:
    • Name: App_server_1
    • Remote root directory: /home/tony/jenkins
    • Labels: stapp01
    • Usage: Use this node as much as possible
    • Launch method: Launch agents via SSH
    • Host: stapp01.stratos.xfusioncorp.com
    • Credentials: stapp01-credentials
    • Host Key Verification Strategy: Non-verifying Verification Strategy
  5. Click Advanced and set:
    • JavaPath: /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java
  6. Click Save

Add App_server_2 Node:

  1. Manage JenkinsNodesNew Node
  2. Enter name: App_server_2
  3. Configure:
    • Name: App_server_2
    • Remote root directory: /home/steve/jenkins
    • Labels: stapp02
    • Host: stapp02.stratos.xfusioncorp.com
    • Credentials: stapp02-credentials
    • JavaPath: /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java
  4. Click Save

Add App_server_3 Node:

  1. Manage JenkinsNodesNew Node
  2. Enter name: App_server_3
  3. Configure:
    • Name: App_server_3
    • Remote root directory: /home/banner/jenkins
    • Labels: stapp03
    • Host: 10.244.195.103 (use IP address since hostname doesn't resolve)
    • Credentials: stapp03-credentials
    • JavaPath: /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java
  4. Click Save

Step 11: Verify All Nodes Are Online

Go to Manage JenkinsNodes. All three nodes should show Online status with a green checkmark.

Nodes online


Troubleshooting Common Issues

Issue 1: UnsupportedClassVersionError

Error:

java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
Enter fullscreen mode Exit fullscreen mode

Cause: Jenkins agent requires Java 17+ but the server has Java 11.

Solution: Install Java 21 and set it as default.

sudo yum install -y java-21-openjdk
sudo alternatives --install /usr/bin/java java /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java 2000
sudo alternatives --set java /usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.1.el9.x86_64/bin/java
Enter fullscreen mode Exit fullscreen mode

Issue 2: "has not been configured as an alternative"

Error:

/usr/lib/jvm/java-21-openjdk-21.0.12.1.1-2.el9.x86_64/bin/java has not been configured as an alternative for java
Enter fullscreen mode Exit fullscreen mode

Cause: Java 21 was not registered as an alternative before using --set.

Solution: Use --install first, then --set.

Issue 3: Wrong Java Path

Error: Path uses -2.el9.x86_64 but the actual path is -2.1.el9.x86_64.

Solution: Verify the exact path:

ls /usr/lib/jvm/
Enter fullscreen mode Exit fullscreen mode

Issue 4: Name or Service Not Known

Error:

stapp03.stratos.xfusioncorp.com: Name or service not known
Enter fullscreen mode Exit fullscreen mode

Cause: The hostname cannot be resolved from the Jenkins server.

Solution: Use the IP address directly in the node configuration.

Issue 5: Jenkins User Cannot Use Sudo

Error:

jenkins is not in the sudoers file.
Enter fullscreen mode Exit fullscreen mode

Cause: The jenkins user doesn't have sudo privileges.

Solution: Use IP addresses in node configuration instead of editing /etc/hosts.


Final Configuration Summary

Node Name Label Remote Root Directory Host JavaPath Status
App_server_1 stapp01 /home/tony/jenkins stapp01.stratos.xfusioncorp.com Java 21 Online
App_server_2 stapp02 /home/steve/jenkins stapp02.stratos.xfusioncorp.com Java 21 Online
App_server_3 stapp03 /home/banner/jenkins 10.244.195.103 Java 21 Online

Key Learnings

  1. Java Version Compatibility: Jenkins agents require Java 17 or higher. Java 21 is recommended.

  2. Alternatives Management: Use alternatives --install to register a new Java version, then alternatives --set to make it default.

  3. JavaPath in Node Configuration: For non-interactive SSH sessions, always specify the full Java binary path in the agent configuration.

  4. Hostname Resolution: If a hostname cannot be resolved, use the IP address directly in the node configuration.

  5. Jenkins User Permissions: The jenkins user may not have sudo access, so plan accordingly.

  6. SSH Key Setup: Generate SSH keys for the jenkins user (not root) and copy them to all target servers.


Benefits of Distributed Builds

With slave nodes configured, you can now:

  • Run jobs in parallel across multiple servers
  • Target specific servers using labels (stapp01, stapp02, stapp03)
  • Reduce load on the Jenkins master
  • Scale horizontally by adding more agents
  • Isolate environments for different build types

Example: Using Node Labels in a Job

node('stapp01') {
    stage('Deploy') {
        sh 'echo "Deploying to App Server 1"'
    }
}
Enter fullscreen mode Exit fullscreen mode

Summary

In this challenge, we successfully:

  1. Generated SSH keys on the Jenkins server
  2. Copied SSH keys to all app servers
  3. Installed Java 21 on all app servers
  4. Registered and set Java 21 as the default version
  5. Created remote root directories on all app servers
  6. Added SSH credentials in Jenkins
  7. Added all three app servers as Jenkins slave nodes
  8. Configured labels and JavaPath for each node
  9. Verified all nodes are online and working

This setup enables Jenkins to distribute build tasks across all app servers, improving performance and allowing server-specific automation tasks. The slave nodes are now ready to execute jobs assigned to them.

Top comments (0)