How To Setup Master Slave In Jenkins
Create another server and install java in it using the command i.e mentioned in installing jenkins on ubuntu, we will consider this server as a slave server
sudo apt install openjdk-8-jdk -y
Setup Jenkins Slave
Create the user and add user to wheel group.
useradd jenkins-slave-01
Create SSH Keys
sudo su - jenkins-slave-01 ssh-keygen -t rsa -N "" -f /home/jenkins-slave-01/.ssh/id_rsa
The private and public keys are created at these locations.
`/home/jenkins-slave-01/.ssh/id_rsa` and `/home/jenkins-slave-01/.ssh/id_rsa.pub`
cd .ssh cat id_rsa.pub > authorized_keys chmod 700 authorized_keys
Configuration on Master
- Copy public key[id_rsa.pub] of slave node to Node’s known_hosts file of Master.
- Configure the node as shown here,go to Manage Jenkins > Manage Nodes > New Node
- Update your jenkins slave label Java
mkdir -p /var/lib/jenkins/.ssh cd /var/lib/jenkins/.ssh ssh-keyscan -H SLAVE-NODE-IP-OR-HOSTNAME >>/var/lib/jenkins/.ssh/known_hosts
ssh-keyscan -H 172.31.*.* >>/var/lib/jenkins/.ssh/known_hosts
chown jenkins:jenkins known_hosts chmod 700 known_hosts
Configure the Slave using Manage Jenkins
Test Jenkins Jobs
1. Create “new item”
2. Enter an item name – My-First-Project
a) Chose Freestyle project
3. Under General Section
a) Choose Restrict where this project can be run
4. Under Build section Execute shell
#!/bin/bash whoami
5. Save your job
6. Build job
7. Check “console output”