About Jenkins Clusters

When multiple tasks are executed simultaneously on Jenkins, the performance of a single machine may reach a bottleneck. Using Jenkins cluster can effectively solve this problem. Letting multiple machines handle these tasks at the same time can spread the pressure and disperse the hidden trouble of single point failure of standalone Jenkins. Jenkins version is 2.190.2;

How to quickly set up a cluster

Most of the preparation work can be saved by Docker. You only need to install Docker on a Linux computer and complete the cluster setup with a few commands and operations.

Environmental information

Three computers will be used in this actual combat environment, and their Settings are all the same, as follows:

  1. Operating system: CentOS Linux Release 7.6.1810
  2. Firewall shutdown
  3. Docker: 1.13.1

The information of the three computers is as follows:

The host name The IP address role
master 192.168.133.131 Jenkins cluster master node, providing Web services
agent1 192.168.133.132 The Jenkins cluster’s working node number one, labeled Maven
agent2 192.168.133.133 Jenkins cluster working node 2, labeled Gradle

It is recommended that the memory of Agent2 nodes be greater than 4G, because the actual operation in the next article will build the Spring-Framework using Agent2, which requires a little more memory.

The preparatory work

  1. All subsequent operations are root;
  2. Create the /usr/local/jenkins folder on each computer

Create Jenkins’ master

  1. Log in to the master machine and run the following command:
docker run \ -u root \ -idt \ --name master \ -p 8080:8080 \ -p 50000:50000 \ -v /usr/local/jenkins:/var/jenkins_home \ - v/var/run/docker. The sock: / var/run/docker. The sock \ jenkinsci/blueocean: 1.19.0Copy the code
  1. If you execute Docker Logs Master, Jenkins’ login key is displayed in the console, as shown in the red box below:

  2. Browser input address: http://192.168.133.131:8080, according to Jenkins login page, as shown in the figure below, the red box position input just copy the secret key can login to log in:

  3. Select the recommended plug-in to install:

  4. Wait for the plug-in to be installed online:

  5. The next step is to create an administrator and use the instance URL, which will be left to your own devices. Now that Jenkins’ master is set up, agent1 and Agent2 are added to the cluster as working nodes.

Join agent1

  1. Add a node on Jenkins web page. The operation is as shown in the figure below. First, enter the node management page:

  2. Add a new node named agent1 as shown below:

  3. The following node details are shown below. Note that the content in the four red boxes should be the same as in the figure:

  4. After successful saving, the machine list will be displayed, as shown in the figure below. The Red Cross on the icon means that the machine is offline (agent1 has not been connected at this time). Click the red box:

  5. As shown in the following figure, the command in the red box is the start command of Agent1, and the machine that executes this command will join the cluster as Agent1:

  6. Note that the agent.jar in the red box in the figure above is a link to download the file named agent.jar to the /usr/local/jenkins directory on agent1 computer;
  7. Log in to the agent1 computer using SSH and run the following command to add Agent1 to the Jenkins cluster:
docker run \ -u root \ -idt \ --name agent \ -v /usr/local/jenkins:/usr/local/jenkins \ bolingcavalry/openjdk-with-sshpass:8u232 \ java -jar /usr/local/jenkins/agent.jar \ -jnlpUrl http://192.168.133.131:8080/computer/agent1/slave-agent.jnlp \ - secret 44c3e8d1531754b8655b53294bbde6dd99b3aaa91a250092d0d3425534ae1058 \ -workDir "/usr/local/jenkins"Copy the code

The second half of the above command, Java -jar…… Is in front of the picture in the red box agent1 startup command, the only change to the agent. The jar to the absolute path/usr/local/Jenkins/agent. The jar

  1. The image of the above command is bolingCavalry/OpenJDk-with-sshpass :8u232. The Dockerfile content is as follows. Such a container can execute SSH commands with the password of the remote machine instead of waiting for the user to enter the password, which makes it easier for shell scripts to execute SSH commands:
FROM openjdk:8u232

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install --assume-yes sshpassCopy the code
  1. Go to Jenkins’ web page and check the node list, as shown in the figure below, agent1 has been added successfully:

Join agent2

Agent2 joins the cluster in the same way as Agent1, except for the following:

  1. Create a node named Agent2 on the Jenkins page
  2. Gradle is the label of Agent2, as shown in the red box below:

  3. In this case, Agent2 also joins successfully:







    At this point, the Jenkins cluster is set up, and the two nodes have different tags. Next articlePipeline In The Jenkins ClusterIn, we create pipeline tasks in this cluster environment and allocate them to different nodes through labels to realize multi-node parallel execution;

Welcome to follow the public number: programmer Xin Chen