Configuring Jenkins Nodes

Posted: September 15, 2018 in Jenkins

Jenkins Slave Nodes are small Java “Client” processes that connect back to a “Master” Jenkins instance over the Java Network Launch Protocol (JNLP).

Task can be executed on Nodes from Jenkins Master

In this example we’ll install Jenkins master and node.

Installing Jenkins Master on CentOS 7

rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Now we will add the package repository address to our repository list with the command below:
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
Update your package manager list to get the latest packages:

yum repolist
Finally, install Jenkins and JAVA with the following command:

yum install java-1.8.0-openjdk jenkins
Starting Jenkins
Jenkins will work as a service, so you can control it using “systemctl” command. start your Jenkins server with the following command:

systemctl start jenkins
If you want to make it run at startup execute the command below as well:

systemctl enable jenkins

copy code from path below and login to Jenkins

1.PNG

Make sure jenkins user has shell enabled:

cat /etc/passwd
jenkins:x:996:994:Jenkins Automation Server:/var/lib/jenkins:/bin/bash

Log in as jenkins user

sudo -iu jenkins

Create private/public key pair

ssh-keygen -t rsa
-bash-4.2$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa):
Created directory '/var/lib/jenkins/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.
Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub

Connect to slave,create .ssh folder and copy public key which will be used for automatic master connection to slave.

ssh root@slave IP mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh root@slaveIP 'cat >> .ssh/authorized_keys'
mkdir ~/bin && cd bin

slave.jar contains information how to connect from slave to master so we need to copy it from master.

Copy slave.jar from master

wget http://slaveIP:8080/jnlpJars/slave.jar

Now on master node click Manage Jenkins

2.png

Click Manage Nodes

3.png

Click New Node specify name click Permanent Agent

4.PNG

Jenkins executor is a process which allows master to run a build on a node
this number specifies maximun mumber of concurrent builds that jenkins may perform on this agent

Remote directory is a folder where Jenkins will perform all its operations

Launch command:ssh root@slaveIP java -jar /root/bin/slave.jar

5.PNG

6.PNG

On slave check that java is running:

ps aux | grep java
[root@localhost bin]# ps aux | grep java
root 13541 8.0 3.9 2673952 95020 ? Ssl 17:45 0:13 java -jar /root/bin/slave.jar
root 14302 0.0 0.0 112660 972 pts/1 R+ 17:48 0:00 grep --color=auto java

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s