We have performed the installation of Jenkins on Ubuntu in the previous guide. Now, it is time to add Jenkins Linux Node (Slave) to the Jenkins Master. For more information on Jenkins, you can follow the following guide: What is Jenkins?
- Ubuntu Server 18.04 (This guide will use this OS)
- A user account with SUDO privileges.
- Java 8 (Jenkins supports this version)
Steps for Jenkins Linux Node (Slave) Installation
- Install Java 8 on Node
- Create a user and configure permissions on Node
- Configure SSH Connection between Master and Node
- Add and configure the Node on Jenkins Web UI
- Finish the installation of Node
1) Install Java 8 on Node
First of all, it would be better to check if Java is installed on the Node. If it is already installed, you can skip this step.
It is currently not installed on the server. So, let’s install the Java JDK 8 on Linux Node (Slave).
sudo apt-get install openjdk-8-jdk
Now, we are going to check if the Java is successfully installed.
Conguratulations! Java JDK 8 is installed successfully on Linux Node!
2) Create a user and configure permissions on Node
On the Linux Node, we need to create a jenkins user that will be in communication with Jenkins Master.
sudo useradd jenkins -U -m -s /bin/bash sudo passwd jenkins
We have created a new user and set a password. Next, we are going to add this user to the sudo group which gives sudo privileges to the user.
sudo usermod -aG sudo jenkins
3) Configure SSH Connection between Master and Node
We have created a user that Jenkins Master will use it to connect to the Node. Next, we are going to configure SSH to establish connections between Jenkins Master and the Jenkins Node.
On the Jenkins Master server:
su - jenkins ssh-keygen
This command will connect to the jenkins user and create the SSH public key and private key on the Master. It will ask you to answer some questions but you may leave them empty as default by pressing enter. We are going to copy the private key content to write it on the configuration of Jenkins Web UI at the next step.
Next, on the master, run the following command for adding public keys to the nodes. The target IP address or Hostname will be Linux Node. It will ask you to enter the password for Node.
Now, we can try the SSH connection between Master and Slave (Node).
Conguratulations! Jenkins Master can create a connection to the Jenkins Node (Slave) successfully!
4) Add and configure the Node on Jenkins Web UI
Next, we are going to add our new Node to the Jenkins on the Web UI.
Go to the Jenkins Web UI and login to the system. Then, click on the Manage Jenkins link on the left menu.
Next, click on the Manage Nodes and Clouds button.
On the left side, click on the New Node menu.
On this page, specify a name for your Jenkins Node and select Permanent Agent option. Then, click on the OK button.
On the next page, fill the required fields as shown below.
- # of executors: 1 (This field specifies how many jobs can be executed at the same time on the node.)
- Remote root directory: /home/jenkins
- Labels: node1 (You can specify a label for nodes to categorize them.)
- Launch method: Launch agents via SSH (This option must be selected as this guide use this connection method. If you are using different connection methods, you may select the other options.)
- Host: 192.168.31.101 (IP address or Hostname of the Node)
- Credentials: jenkins (This credential will be set up at the next step.)
Click on the Add button near to Credentials sections.
Click on the Jenkins from the list.
On this page, select SSH Username with private key option from Kind. Then, fill the Username field with jenkins. Next, select the Enter directly option. Then, paste the private key content to the text area which we have got it from previous step. Click on the Add button.
After adding credentials, click on the Save button on the main page.
After that, it will redirect you to Node List page. So, the node we just added has been added to the list.
Next, click on the Node Name and then go to the Log menu on the left side.
Conguratulations! You have added a new node to the Jenkins successfully!