Configure Jenkins master — slave architecture in AWS

This document will explain how we can configure the master slave architecture in AWS ubuntu machine. This tutorial is based on AWS ubuntu machine and using command line interface .

Architecture -

Jenkins Master — Slave Architecture

Prerequisites -
1. At least two AWS EC2 instances with Ubuntu OS installed.

Configure Jenkins Master -

1. Launch EC2 instance 1 in terminal.

2. Ubuntu uses apt-get to install packages. First user needs to update the apt-get once the instance is launched.
$sudo apt-get update

3. Install Java. Java will be required to run the Jenkins.
$sudo apt-get install -y openjdk-8-jdk

3. Ubuntu will use jenkins debian package. To use this repository first user needs to add the key in the system
$sudo wget -q -O — | sudo apt-key add -
you will get a message OK if it’s successfully added.

4. Then user has top add the entry of debian binary in source.list
$sudo sh -c ‘echo deb binary/ > /etc/apt/sources.list.d/jenkins.list’

5. Once this entry has been added apt-get needs to be updated again.
$sudo apt-get update

6. Now user can install jenkins
$sudo apt-get install -y jenkins
This will install the jenkins in the system.

7. Verify the installation by checking the status of jenkins service after installation. It should be active.
$service jenkins status

8. If jenkins is successfully installed now open the url of the ec2 instance in host browser
you will get the following screen to be opened

9. The Administrator password will be stored in </var/lib/jenkins/secrets/initialAdminPassword > path of Jenkins master machine. Copy the password and paste it here complete the setup with default options.

10. Once Jenkins server is successfully configured then click on Manage Jenkins.

11. Then move to Configure Global Security.

12. Select option Random for the settings of Security port for inbound agents. And save the settings.

13. Now go to Manage Nodes and Clouds section under Manage Jenkins.

14. Click on New Node and give the name of the node (ex. Slave-1) and select the Permanent Agent option and click on OK

15. Now in the node configuration in the Remote root directory give a valid path of the slave machine. At the time of executions workspace will be created inside this directory (ex. /home/ubuntu/Jenkins).

16. Select the launch method as Launch agent by connecting it to the master.

17. Click on Save and that’s it. Jenkins master configuration is done. Now you can see the list of nodes like the following. There will red cross mark for the slave node as the node has not been configured yet.

18. Click on the slave node. There you will get the link to download two important files which will be required for configuring the slave. 1. agent.jar, 2. Slave-agent.jnlp
Also note down the first command mentioned under Run from agent command line section

Configure Jenkins slave -

1. Launch the second EC2 instance.

2. First user needs to update the apt-get once the instance is launched.
$sudo apt-get update

3. Install Java. Java will be required to run the jar file which will configure the system as Jenkins slave.
$sudo apt-get install -y openjdk-8-jdk

4. Copy the downloaded file to the slave instance. You can use file transfer tools like FileZilla or also can use terminal in case of mac or linux host machine (ex. sudo scp -i </Path_to_awsKey/Key_Name.pem> </path_of_source_file>

5. Navigate to directory in slave machine where files are copied and run the command copied in the step 19 of the previous section. This will configure the instance as Jenkins slave machine and will show the message Connected.

6. That’s it. Jenkins node has been successfully configured. To verify open the browser tab in the host machine where Jenkins is opened and go to the nodes section. You will observe that node machine is listed there and also the red cross mark on it is no longer visible.

To execute a job in the slave, you have to configure the the slave machine in the job settings. Enter the node name in the Restrict where this project can be run section.

Software Development Engineer in Test | DevOps Engineer | Python Developer