Jenkins - How To Add a Agent node or Slave Node

1. Check the slave node and necessary packages(java) are installed:
 [root@nx-psowifi ~]# cat /etc/redhat-release  
 CentOS Linux release 7.4.1708 (Core)

 [root@nx-psowifi ~]# java -version  
 openjdk version "1.8.0_151"  
 OpenJDK Runtime Environment (build 1.8.0_151-b12)  
 OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)  
If Java-8 is not installed, you may install it with the command: yum -y install java-1.8.0-openjdk

2. Create a user(jenkins) on the slave node:
 [root@nx-psowifi ~]# useradd -d /var/lib/jenkins jenkins  
 [root@nx-psowifi ~]# id jenkins  
 uid=454(jenkins) gid=100(users) groups=100(users)  
This user and the folder path will be used in Jenkins side configuration below.

3. Generate ssh key for server to login:
In the slave node go to some folder, maybe /tmp, and type ssh-keygen. Follow the prompts, and do note down the passphrase entered.
 [root@nx-psowifi tmp]# ssh-keygen  
 Generating public/private rsa key pair.  
 Enter file in which to save the key (/root/.ssh/id_rsa):  
 Enter passphrase (empty for no passphrase):  
 Enter same passphrase again:  
 Your identification has been saved in /root/.ssh/id_rsa.  
 Your public key has been saved in /root/.ssh/id_rsa.pub.  
 The key fingerprint is:  
 SHA256:wZ/hs075xboarhPAJyFsiXz9PdMAw4CDCbphgguRSkk root@nx-psowifi  
 The key's randomart image is:  
 +---[RSA 2048]----+  
 |+E.= +.oo.    |  
 |++= O o....   |  
 |O. o + oo..o   |  
 |=+  + o++o.  |  
 |o   +S =o   |  
 |    . + .  |  
 |     .=  o |  
 |    .+ o o  |  
 |    .o+.+.  |  
 +----[SHA256]-----+  
The above will generate 2 key files in .ssh folder in the location(specified above).
[general@nx-psowifi ~]$ ls /root/.ssh/
id_rsa  id_rsa.pub

The "id_rsa.pub" is the public key.
The "id_rsa" private key will be used in Jenkins UI while configuring the slave node.

4. Copy public key to the authorized_keys file of jenkins user, and change owner of the file:
 [root@nx-psowifi ~]# mkdir /var/lib/jenkins/.ssh  
 [root@nx-psowifi ~]# cp /root/.ssh/id_rsa.pub /var/lib/jenkins/.ssh/authorized_keys  
 [root@nx-psowifi ~]# cd /var/lib/jenkins/.ssh/; chown jenkins:users authorized_keys  

5. Configure Jenkins to add the slave node:
Log in to Jenkins UI, go to Manage Jenkins, then Manage Nodes, then click New Node, give your node a name, then select Permanent Agent and click OK.
Fill up or select all the appropriate values as in the screenshot below, and wait before clicking save.

For Credentials, select the button Add -> Jenkins, and you'll get a screen as below:

Enter as below:
Username = jenkins
Private Key = select "Enter directly". Copy the contents of private key "id_rsa" from step3 above, into the Key field.
Passphrase = Enter the passpharse, noted down during step3.
You may enter or leave blank a descriptive id and description, then click Add.
You may now save the New Node creation.

6. Check the new slave node is working fine:
Go to Jenkins UI, go to Manage Jenkins, then Manage Nodes, then click our just created node name, then in the subsequent page click "Launch agent" button.
If all configuration are fine, you should see output in the same page something like below:
 ...........  
 ...........  
 [12/20/18 00:05:05] [SSH] Checking java version of java  
 [12/20/18 00:05:05] [SSH] java -version returned 1.8.0_151.  
 [12/20/18 00:05:05] [SSH] Starting sftp client.  
 [12/20/18 00:05:05] [SSH] Copying latest slave.jar...  
 [12/20/18 00:05:06] [SSH] Copied 745,674 bytes.  
 Expanded the channel window size to 4MB  
 [12/20/18 00:05:06] [SSH] Starting slave process: cd "/var/lib/jenkins" && exec java -jar slave.jar  
 <===[JENKINS REMOTING CAPACITY]===>channel started  
 Remoting version: 3.14  
 This is a Unix agent  
 Evacuated stdout  
 Agent successfully connected and online  
 ...  

1 comment:

  1. Easy "water hack" burns 2 lbs OVERNIGHT

    At least 160 thousand men and women are trying a simple and secret "water hack" to lose 1-2lbs every night while they sleep.

    It is effective and it works on anybody.

    You can do it yourself by following these easy steps:

    1) Hold a clear glass and fill it half glass

    2) Proceed to learn this crazy hack

    you'll be 1-2lbs skinnier the very next day!

    ReplyDelete