How to Set Up Jenkins Master-Slave Architecture: A Step-by-Step Guide

Jenkins is a powerful open-source automation tool that facilitates Continuous Integration (CI) and Continuous Delivery (CD). One of the key features that makes Jenkins highly scalable is its Master-Slave architecture. This setup allows Jenkins to delegate tasks to other machines (Slaves) while maintaining centralized control through the Master server.

In this article, we’ll walk through the entire process of setting up a Jenkins Master-Slave architecture from scratch. By the end of this guide, you'll have a fully functional Jenkins setup capable of distributing build and test tasks across multiple servers.

What is Jenkins Master-Slave Architecture?

In Jenkins:

  • Master: The Jenkins Master server is the main server that manages the Jenkins environment. It handles job scheduling, configuration management, and provides the user interface to configure Jenkins jobs, plugins, etc.

  • Slave: A Jenkins Slave is a remote machine that performs the actual work (such as building, testing, or deploying) that the Jenkins Master schedules. By adding Slaves, you can scale your Jenkins environment, improve performance, and avoid overloading the Master server.

The Master-Slave architecture allows you to distribute workloads across multiple machines, improving the overall speed and efficiency of your Jenkins pipelines.


Prerequisites

Before you begin, make sure you have:

  • Two servers: One for Jenkins Master and one for Jenkins Slave. These can be virtual machines, physical machines, or even cloud-based instances.

  • Linux knowledge: Basic knowledge of Linux commands for managing servers.

  • SSH access: SSH access to both Master and Slave servers.

  • Root or sudo access: Required for installation and configuration tasks.

  • A working network connection between the Master and Slave.


Step 1: Install Jenkins on the Master Server

  1. Choose a server for the Jenkins Master:
    This will be the central point of control for your Jenkins setup.

  2. Install Jenkins on the Master:
    Depending on your Linux distribution, you can install Jenkins as follows:

    • On Ubuntu/Debian:

        sudo apt update
        sudo apt install openjdk-11-jdk
        sudo apt install wget
        wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee -a /etc/apt/trusted.gpg.d/jenkins.asc
        sudo sh -c 'echo deb http://pkg.jenkins.io/debian/ stable main > /etc/apt/sources.list.d/jenkins.list'
        sudo apt update
        sudo apt install jenkins
      
    • On CentOS/RHEL:

        sudo yum install java-11-openjdk-devel
        sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
        sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
        sudo yum install jenkins
      
  3. Start Jenkins:
    After installation, start Jenkins and enable it to start on boot:

     sudo systemctl start jenkins
     sudo systemctl enable jenkins
    
  4. Access Jenkins Dashboard:
    In your browser, navigate to http://<master-server-ip>:8080 to access the Jenkins setup wizard.


Step 2: Install Jenkins on the Slave Server

  1. Choose a server for the Jenkins Slave:
    This machine will perform the actual work, such as running builds, tests, and other tasks.

  2. Install Jenkins on the Slave:
    You can install Jenkins on the Slave server following the same steps as for the Master server.


Step 3: Set Up SSH Between Jenkins Master and Slave

  1. Set Up SSH Key Authentication:
    To allow Jenkins to communicate with the Slave, you need to set up SSH key-based authentication.

    • On the Master server, generate SSH keys:

        su - jenkins
        ssh-keygen -t rsa
      
    • Copy the public key to the Slave server:

        ssh-copy-id jenkins@<slave-server-ip>
      
  1. Verify SSH Access:
    Test the SSH connection to make sure it’s working:
    ssh jenkins@<slave-server-ip>

Step 4: Set Up Password Authentication on Both Master and Slave

  1. Allow Password Authentication (if needed): On both the Master and Slave servers, edit the SSH configuration to allow password-based authentication (especially for environments that prefer password auth over SSH keys).

    • Open the SSH configuration file:

        sudo vi /etc/ssh/sshd_config
      
    • Find and modify the following lines:

        PasswordAuthentication yes
        PubkeyAuthentication yes
      
    • Restart SSH to apply the changes:

        sudo systemctl restart sshd
      
  1. Set the Jenkins User Password: On both Master and Slave, set the password for the Jenkins user:
    sudo passwd jenkins

This allows SSH access to the Jenkins user using a password if SSH keys aren’t used.


Step 5: Configure Jenkins Master to Recognize the Slave

  1. Login to Jenkins Dashboard:
    On the Jenkins Master, open your browser and go to http://<master-server-ip>:8080.

  2. Manage Jenkins:
    From the Jenkins dashboard, click on Manage Jenkins.

  3. Add a New Node (Slave):

    • Click on Manage Nodes.

    • Click New Node.

    • Enter a name for the Slave node and select Permanent Agent.

    • Configure the following:

      • Number of Executors: How many jobs the Slave can handle concurrently.

      • Remote Root Directory: The directory on the Slave where Jenkins will store files (e.g., /home/jenkins).

      • Labels: You can use labels to specify which jobs should run on the Slave.

      • Launch Method: Choose Launch agent via SSH.

      • Host: Enter the IP address of the Slave.

      • Credentials: Add SSH credentials:

        • If using Password Authentication, use the username and password.

        • If using SSH Key Authentication, add SSH credentials using the private key generated earlier.

      • Host Key Verification Strategy: Choose Non-verifying verification strategy.

      • Availability: Select Keep this agent online as much as possible.

  4. Save and Test Connection:
    After saving, Jenkins will try to connect to the Slave via SSH. If everything is configured correctly, the Slave node will appear as online in the Jenkins Dashboard.


Step 6: Verify the Setup

To verify that your Master-Slave setup is working:

  1. Create a Test Job:
    Create a simple Jenkins job and assign it to the Slave node.

  2. Run the Job:
    Execute the job, and Jenkins should run it on the Slave node. You should be able to monitor the job’s progress through the Jenkins dashboard.


Conclusion

Congratulations! You’ve successfully set up Jenkins Master-Slave architecture. This setup allows Jenkins to distribute build and test tasks across multiple servers, improving efficiency and scalability.

0
Subscribe to my newsletter

Read articles from Chinnayya Chintha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chinnayya Chintha
Chinnayya Chintha

I am 𝗖𝗵𝗶𝗻𝗻𝗮𝘆𝘆𝗮 𝗖𝗵𝗶𝗻𝘁𝗵𝗮, 𝗮 𝗿𝗲𝘀𝘂𝗹𝘁𝘀-𝗱𝗿𝗶𝘃𝗲𝗻 𝗦𝗶𝘁𝗲 𝗥𝗲𝗹𝗶𝗮𝗯𝗶𝗹𝗶𝘁𝘆 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿 (𝗦𝗥𝗘) with proven expertise in 𝗮𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗻𝗴, 𝗮𝗻𝗱 𝗺𝗮𝗻𝗮𝗴𝗶𝗻𝗴 𝘀𝗲𝗰𝘂𝗿𝗲, 𝘀𝗰𝗮𝗹𝗮𝗯𝗹𝗲, 𝗮𝗻𝗱 𝗿𝗲𝗹𝗶𝗮𝗯𝗹𝗲 𝗶𝗻𝗳𝗿𝗮𝘀𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻𝘀. My experience spans 𝗰𝗹𝗼𝘂𝗱-𝗻𝗮𝘁𝗶𝘃𝗲 𝘁𝗲𝗰𝗵𝗻𝗼𝗹𝗼𝗴𝗶𝗲𝘀, 𝗖𝗜/𝗖𝗗 𝗮𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻, 𝗮𝗻𝗱 𝗜𝗻𝗳𝗿𝗮𝘀𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲 𝗮𝘀 𝗖𝗼𝗱𝗲 (𝗜𝗮𝗖), enabling me to deliver 𝗵𝗶𝗴𝗵-𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗶𝗻𝗴 𝘀𝘆𝘀𝘁𝗲𝗺𝘀 that enhance operational efficiency and drive innovation. As a 𝗙𝗿𝗲𝗲𝗹𝗮𝗻𝗰𝗲 𝗦𝗶𝘁𝗲 𝗥𝗲𝗹𝗶𝗮𝗯𝗶𝗹𝗶𝘁𝘆 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿, I specialize in: ✅𝗜𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁𝗶𝗻𝗴 𝘀𝗲𝗰𝘂𝗿𝗲 𝗮𝗻𝗱 𝘀𝗰𝗮𝗹𝗮𝗯𝗹𝗲 𝗽𝗮𝘆𝗺𝗲𝗻𝘁 𝗴𝗮𝘁𝗲𝘄𝗮𝘆 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻𝘀 𝘂𝘀𝗶𝗻𝗴 𝗔𝗪𝗦 𝘀𝗲𝗿𝘃𝗶𝗰𝗲𝘀 𝗹𝗶𝗸𝗲 𝗔𝗣𝗜 𝗚𝗮𝘁𝗲𝘄𝗮𝘆, 𝗟𝗮𝗺𝗯𝗱𝗮, 𝗮𝗻𝗱 𝗗𝘆𝗻𝗮𝗺𝗼𝗗𝗕.. ✅𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗻𝗴 𝗶𝗻𝗳𝗿𝗮𝘀𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲 𝗽𝗿𝗼𝘃𝗶𝘀𝗶𝗼𝗻𝗶𝗻𝗴 with 𝗧𝗲𝗿𝗿𝗮𝗳𝗼𝗿𝗺. ✅𝗢𝗽𝘁𝗶𝗺𝗶𝘇𝗶𝗻𝗴 𝗺𝗼𝗻𝗶𝘁𝗼𝗿𝗶𝗻𝗴 using 𝗖𝗹𝗼𝘂𝗱𝗪𝗮𝘁𝗰𝗵. ✅Ensuring compliance with 𝗣𝗖𝗜-𝗗𝗦𝗦 𝘀𝘁𝗮𝗻𝗱𝗮𝗿𝗱𝘀 through 𝗲𝗻𝗰𝗿𝘆𝗽𝘁𝗶𝗼𝗻 𝗺𝗲𝗰𝗵𝗮𝗻𝗶𝘀𝗺𝘀 ✅implemented with 𝗔𝗪𝗦 𝗞𝗠𝗦 and 𝗦𝗲𝗰𝗿𝗲𝘁𝘀 𝗠𝗮𝗻𝗮𝗴𝗲𝗿. These efforts have resulted in 𝗲𝗻𝗵𝗮𝗻𝗰𝗲𝗱 𝘁𝗿𝗮𝗻𝘀𝗮𝗰𝘁𝗶𝗼𝗻 𝗿𝗲𝗹𝗶𝗮𝗯𝗶𝗹𝗶𝘁𝘆 and 𝘀𝘁𝗿𝗲𝗮𝗺𝗹𝗶𝗻𝗲𝗱 𝗼𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝘄𝗼𝗿𝗸𝗳𝗹𝗼𝘄𝘀 for payment processing systems. I am passionate about 𝗺𝗲𝗻𝘁𝗼𝗿𝗶𝗻𝗴 𝗮𝗻𝗱 𝗸𝗻𝗼𝘄𝗹𝗲𝗱𝗴𝗲 𝘀𝗵𝗮𝗿𝗶𝗻𝗴, having delivered 𝗵𝗮𝗻𝗱𝘀-𝗼𝗻 𝘁𝗿𝗮𝗶𝗻𝗶𝗻𝗴 in 𝗰𝗹𝗼𝘂𝗱 𝘁𝗲𝗰𝗵𝗻𝗼𝗹𝗼𝗴𝗶𝗲𝘀, 𝗞𝘂𝗯𝗲𝗿𝗻𝗲𝘁𝗲𝘀, 𝗮𝗻𝗱 𝗮𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻. My proactive approach helps me anticipate system challenges and create 𝗿𝗼𝗯𝘂𝘀𝘁, 𝘀𝗰𝗮𝗹𝗮𝗯𝗹𝗲 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻𝘀 𝘁𝗵𝗮𝘁 𝗲𝗻𝗵𝗮𝗻𝗰𝗲 𝘀𝗲𝗰𝘂𝗿𝗶𝘁𝘆, 𝗰𝗼𝗺𝗽𝗹𝗶𝗮𝗻𝗰𝗲, 𝗮𝗻𝗱 𝗼𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝗲𝗳𝗳𝗶𝗰𝗶𝗲𝗻𝗰𝘆. Dedicated to 𝗰𝗼𝗻𝘁𝗶𝗻𝘂𝗼𝘂𝘀 𝗹𝗲𝗮𝗿𝗻𝗶𝗻𝗴, I stay updated with 𝗲𝗺𝗲𝗿𝗴𝗶𝗻𝗴 𝘁𝗲𝗰𝗵𝗻𝗼𝗹𝗼𝗴𝗶𝗲𝘀 and thrive on contributing to 𝘁𝗿𝗮𝗻𝘀𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝘃𝗲 𝗽𝗿𝗼𝗷𝗲𝗰𝘁𝘀 that push boundaries in technology.