Basic information about Jenkins Master and Slave
Jenkins Master
Jenkins Master Creation link: How to Create Jenkins Master
Step 1 : Create another Jenkins Slave machine instance in AWS EC2
Create another user in the Jenkins Slave machine as Jenkins-slave and follow the below commands
Step 2 - $ sudo su
Step 3 - sudo adduser --home /home/jenkins-slave --shell /bin/bash --ingroup admin jenkins-slave
Logged into created user using
Step 4 - $ sudo su - jenkins-slave
Step 5 : Now type ssh-keygen (and then simply enter four times, do not give any password)
Set no password authentication in /etc/sudoers
Step 6 - vi /etc/sudoers and type the following command in the sudoers file, hit the "Esc" key from keyboard and save the file by typing "wq!"
Step 7 : Copy the "Private key (id_rsa)" from ~/.ssh/id_rsa file by typing below commad
cat ~/.ssh/id_rsa or Go To ---> .ssh folder "cd .ssh"
Step 8 : Go to Master Jenkins and type the jenkins URL like "http://3.19.211.7:8080/"
Step 9 : Add SSH Keys from Master to Slave
Execute the below command in Jenkins master Ec2.
sudo cat ~/.ssh/id_rsa.pub
Copy the output of the above command:
Step 10 : Now go to Slave node and execute the below command and paste the "id_rsa.pub" key to authorized_keys
jenkins-slave@ip-172-31-33-151:~/.ssh$ vi authorized_keys
Once you pasted the public keys in the above file in Slave, come out of the file by entering wq! and enter again
Now go into master node
ubuntu@ip-172-31-41-76:~$ sudo ssh jenkins-slave@172.31.33.151
this is to make sure the master is able to connect the slave node. once you are successfully logged into the slave, type exit to come out of the slave.
And type the below commands
Step # Register slave node in Jenkins:
Now to go Jenkins Master, manage jenkins, manage nodes.
8. Select the "SSH Username with Private Key" and fill the necessary information as below image
9. type the command cat ~/.ssh/id_rsa looks like the below image (text hidden in the image)
(Make sure you copy the whole key including the below without missing anything)
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY----
10 . Paste in the "Private key" in the text area as mentioned in below image
11. After that Select the "Username" from [Credentials] drop-down list as shown in below image and click on [SAVE] button.
Step # : Create a new Jenkins Job in Jenkins Master
Now you can kick start building the jobs, you will see Jenkins master runs jobs in slave nodes.
Jenkins Master
Your main Jenkins server is the Master. The Master’s job is to handle:
- Scheduling build jobs.
- Dispatching builds to the slaves for the actual execution.
- Monitor the slaves (possibly taking them online and offline as required).
- Recording and presenting the build results.
- A Master instance of Jenkins can also execute build jobs directly.
Jenkins Slave
A Slave is a Java executable that runs on a remote machine. Following are the characteristics of Jenkins Slaves:
- It hears requests from the Jenkins Master instance.
- Slaves can run on a variety of operating systems.
- The job of a Slave is to do as they are told to, which involves executing build jobs dispatched by the Master.
- You can configure a project to always run on a particular Slave machine, or a particular type of Slave machine, or simply let Jenkins pick the next available Slave.
Let's see how to configure both Jenkins master and slave nodes on Ubuntu EC2.
Jenkins Master Creation link: How to Create Jenkins Master
Step 1 : Create another Jenkins Slave machine instance in AWS EC2
Create another user in the Jenkins Slave machine as Jenkins-slave and follow the below commands
Step 2 - $ sudo su
Step 3 - sudo adduser --home /home/jenkins-slave --shell /bin/bash --ingroup admin jenkins-slave
Logged into created user using
Step 4 - $ sudo su - jenkins-slave
Step 5 : Now type ssh-keygen (and then simply enter four times, do not give any password)
Set no password authentication in /etc/sudoers
Step 6 - vi /etc/sudoers and type the following command in the sudoers file, hit the "Esc" key from keyboard and save the file by typing "wq!"
Step 7 : Copy the "Private key (id_rsa)" from ~/.ssh/id_rsa file by typing below commad
cat ~/.ssh/id_rsa or Go To ---> .ssh folder "cd .ssh"
Step 9 : Add SSH Keys from Master to Slave
Execute the below command in Jenkins master Ec2.
sudo cat ~/.ssh/id_rsa.pub
Copy the output of the above command:
Step 10 : Now go to Slave node and execute the below command and paste the "id_rsa.pub" key to authorized_keys
jenkins-slave@ip-172-31-33-151:~/.ssh$ vi authorized_keys
Once you pasted the public keys in the above file in Slave, come out of the file by entering wq! and enter again
Now go into master node
ubuntu@ip-172-31-41-76:~$ sudo ssh jenkins-slave@172.31.33.151
this is to make sure the master is able to connect the slave node. once you are successfully logged into the slave, type exit to come out of the slave.
And type the below commands
Step # Register slave node in Jenkins:
Now to go Jenkins Master, manage jenkins, manage nodes.
- Click on new node.
- give the name and check permanent agent,
- give a name and no of executors as 1 or 2 or based on your requirement.
- enter /home/Jenkins-slave as a remote directory.
- select launch method as Launch slaves nodes via SSH.
- enter Slave node private ip address as Host.
7. Click on [Add] and click on [Jenkins] it will redirect to another window
8. Select the "SSH Username with Private Key" and fill the necessary information as below image
9. type the command cat ~/.ssh/id_rsa looks like the below image (text hidden in the image)
(Make sure you copy the whole key including the below without missing anything)
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY----
10 . Paste in the "Private key" in the text area as mentioned in below image
11. After that Select the "Username" from [Credentials] drop-down list as shown in below image and click on [SAVE] button.
Step # : Create a new Jenkins Job in Jenkins Master
Step #: Type Project Name and Project Type and click on the [OK] button
Step #: Go To -> General tab and check the [Restrict where this project can be run] and enter the slave machine name
Step #: Click on "Build Environment" and select Build type as "Execute Shell" and click on [save] button by typing some as like in below
Step #: Go To Jenkins Dashboard and click on [Build Now] to run the job and check the output
Step #: Go to Jenkins Slave Machine and type the below commands
sudo su - jenkins-slave and press "ls"
Type "cd workspace" and press "ls" select desired like "Jenkins-Slave-job" and press "ls" again to verify the text file created or not.
Now you can kick start building the jobs, you will see Jenkins master runs jobs in slave nodes.
No comments:
Post a Comment