Setup Jenkins Master Slave Configuration on AWS

In this tutorial, we will learn how to setup Jenkins Master Slave configuration in AWS EC2 server.

Prerequisites:

1. Launch 2 AWS EC2 Linux instances (Follow Here).

2. Configure Jenkins on an EC2 Linux instance which will act as  Master Node (Follow Here).

3. Second EC2 Linux Server will act as a Slave Node for Jenkins.

Configure Jenkins Slave Node:

Create user, ssh keys and copy it to authorized_keys.

sudo useradd jenkins-slave1
sudo su - jenkins-slave1
ssh-keygen -t rsa -N "" -f /home/jenkins-slave1/.ssh/id_rsa
cd .ssh 
cat id_rsa.pub > authorized_keys 
chmod 700 authorized_keys

Configure Jenkins Master Node:

Copy the slave node’s public key to master node’s known_hosts file.

sudo mkdir -p /var/lib/jenkins/.ssh
cd /var/lib/jenkins/.ssh
cd ..
sudo chmod 777 .ssh
cd .ssh
sudo ssh-keyscan -H SLAVE_NODE_PRIVATE_IP >>/var/lib/jenkins/.ssh/known_hosts
sudo chown jenkins:jenkins known_hosts
sudo chmod 700 known_hosts

Configure New Node in Jenkins:

1. Click on Manage Jenkins.

2. Click on Manage Nodes and Clouds

3. Click on New Node

4. Enter Node name and select Permanent Agent. Click OK

5. Enter node configuration details as shown below.

6. In Credentials, Click Add -> Jenkins

7. In Add Credentials, choose kind as “SSH Username with private key”

8. In Username field, enter the same username which we created on Slave Node – jenkins-slave1

9. In Private Key, choose Enter directly

10. Go to Slave EC2 server and copy the private key.

sudo su - jenkins-slave1
cd .ssh
more id_rsa

11. Paste the key in the Private key field in Jenkins.

12. Click on Add.

13. In the Node Configuration page choose the new credential.

14. Click on Save.

15. Click on the new node (slave1) and select “log”.

16. “Agent successfully connected and online” is displayed in the logs.

Share

Bijan Patel

Founder & Creator of QAScript | 12+ years of IT Experience | Full Stack Automation Engineer | Blogger | Trainer

You may also like...

Leave a Reply

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

error: Content is protected !!