Skip to main content

Jenkins Master Slave Setup

Generally, the Jenkins master node will be only used for storing configurations. The slaves should be used for the build. It is possible to configure multiple slaves on a Jenkins master node. So, in this post, we’ll check the Jenkins Master Slave setup.

If you are new here, please go through the following posts to setup your Jenkins Master Node:

Here, I am using a CentOS 6 server as Slave.

Step 1: Install Java

First, install and configure Java on your new Slave machine.

yum install java-1.8.0-openjdk-devel.x86_64
cp /etc/profile /etc/profile_orig
echo -e "export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk" >> /etc/profile
echo -e "export JRE_HOME=/usr/lib/jvm/jre" >> /etc/profile
source /etc/profile

Step 2: Add a sudo user for Jenkins

Next, we can add a new user account on the Slave system so that the Jenkins Master can communicate with the Slave.

useradd -s /bin/bash -m -d /home/jenkins jenkins

The above command will create a new user “jenkins” with its home directory pointing to “/home/jenkins”.

Reset the password associated with this account using:

passwd jenkins

Now, add this new user to the sudo users list. For this, you would need to add the following entry to the “/etc/sudoers” file.

jenkins ALL=(ALL) ALL

Step 3: Setting up SSH Key authentication for Jenkins

Now, on your Jenkins Master node create a new SSH Key pair for Jenkins user.

su - jenkins
Sample Output:
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa): 
Created directory '/var/lib/jenkins/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.
Your public key has been saved in /var/lib/jenkins/.ssh/
The key fingerprint is:
SHA256:oYanYm2XE6vC2YizTCGal8PWrvV+O/VdeE5uUxCYmU4 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| = |
| E . |
| . o . |
| . . . . . |
|.. . = S o |
|oo.+ + + . . =|
|o+O+* = . . . *.|
|=+=*.+ .o . ..+|
|.+.oo.o..o ..|

In the above output, the public key is located in /var/lib/jenkins/.ssh/ The private key (identification) is now located in /var/lib/jenkins/.ssh/id_rsa.

Now, copy the SSH public key into the slave machine’s authorized_keys file with the below ssh-copy-id command:

ssh-copy-id [email protected]

Replace with your Jenkins Slave Server IP Address.

In case, the above command didn’t work, manually copy the content of the Master node’s SSH public key “/var/lib/jenkins/.ssh/” to the Slave’s SSH authorized_keys file located in “/home/jenkins/.ssh/authorized_keys“.

Step 4: Add the Node to Jenkins Master

Go to Manage Jenkins –> Manage nodes and proceed with the Jenkins Master Slave configuration.

Select new node from the left pane. Add a proper “Node Name” and click OK after selecting the “Permanent Agent” radio button.

On the next page,  add all the necessary details. In the “# of executors”, enter the maximum number of concurrent builds that Jenkins may perform on this Slave. Generally, this is set as per no of processor cores available on the remote machine.

Select the Launch Method as “Launch agent agents via SSH”  and enter the Slave credentials. 

Once done, enter scroll down and Click on the Save button. It will take a few minutes to bring the slave node online. You can check the logs by clicking the slave machine name and then click logs:

You can see something like below on the logs if the Slave is successfully connected to the Master.

<===[JENKINS REMOTING CAPACITY]===>channel started
Remoting version: 3.21.1
This is a Unix agent
Evacuated stdout
Agent successfully connected and online

That’s it. You are done with the Jekins Master Slave setup. Any issues? Leave a comment below.

Jenkins Master Slave Setup
4 (80%) 2 vote[s]


TheGeeksAlive is all about Linux, Server Administration, Web Hosting and other Open Source Technologies.