Setup Jenkins Master and Slave on Ubuntu 16.04

Jenkins is an open source continuous Integration (CI) tools based on Java. Thousand of plugin supported which greatly enhance the functionality of core Jenkins. In this article, we setup jenkins master and slave on ubuntu 16.04, We will learn to set up the Jenkins master node, and then add other Ubuntu nodes as Jenkins slaves.

Jenkins master-slave architecture allows to distribute load across multiple machines, helping drive builds, tests and deployments across multiple platforms faster.

At the time of writing this article, Jenkins version – 2.121.3

Step 1 – Add Jenkins PPA

wget -q -O - | sudo apt-key add -
sudo sh -c 'echo deb binary/ > /etc/apt/sources.list.d/jenkins.list'

Step 2 – Install Jenkins

apt-get update
apt-get install openjdk-8-jdk
apt-get install jenkins

Note: Jenkins recommended to have atleast java 8 or newer version.

By default Jenkins run on port 8080, If you want to change to something else, feel free to do it by editing /etc/default/jenkins configuration file and update HTTP_PORT value to <your_port>

Step 3 – Access Jenkins Web Interface

Access your server on port 8080 in your favorite web browser. The default installation password can be found at /var/lib/jenkins/secrets/initialAdminPassword as showing in below image.

jenkins password

Step 4 – Generate ssh key on jenkins master node

Setup key based authentication to communicate with the jenkins slave node.

sudo -iu jenkins
ssh-keygen -t rsa
ssh root@ip_slave_node mkdir -p .ssh
cat .ssh/ | ssh root@ip_slave_node 'cat >> .ssh/authorized_keys'

Above command generate key and copy over to the slave node inside /root/.ssh/authorized_keys file.

To Access Slave Node:

ssh root@ip_slave_node
wget http://master_server_ip:8080/jnlpJars/slave.jar
apt-get install default-jre
mkdir jenkins

Above command to install slave agent on slave node.

Note: jenkins directory is created to store Jenkins slave jobs config here.

Go to Jenkins Dashboard

jenkins dashboard

Now, we need to start jenkins slave agent via ssh

Login to Jenkins dashboard and navigate to Manage Jenkins >> Manage Plugins >> Available Tab and search for ssh slave plugins, then click install without restart.

jenkins plugin

Now To create node, Navigate to Mange Jenkins >> Manage Nodes >> New Node

jenkins node

Provide any name to the node (i.e slave-1) and check Permanent Agent, then click OK.

jenkins slave

Note: Remote root directory is the path where we created jenkins directory on slave node. Select Launch method as showing in above image >> Launch command

ssh root@ip_slave_node java -jar /root/slave.jar

Then, Click Save.

Keep clicking Refresh status button, you see your slave node status is online as showing in below image.

slave node status

Stay Tune for more info.

Add a Comment

Your email address will not be published. Required fields are marked *