虚拟化容器,大数据,DBA,中间件,监控。

Jenkins 多实例配置

20 12月
作者:admin|分类:系统运维

Jenkins多实例配置


单台Jenkins服务器可以满足企业测试环境及生产环境使用Jenkins自动部署+测试平台,如果每天更新发布多个WEB网站,Jenkins需要同时处理很多的任务。基于Jenkins分布式,也即多Slave方式可以缓解Jenkins服务器的压力,Jenkins多实例架构如图所示,可以在Windows、Linux、MAC等操作系统上执行Slave。

Jenkins在没有slavle的时候其实都是在一台机器上面,包括拉取代码,构建,部署其实都是在jenkins本机上面做的,当你的任务项目非常多的时候。任务会排列在队列当中等待。当前jenkins的负载会很高,因为像java的maven构建会涉及到很多的i/o,导致构建非常的慢。

面对这种使用master slave,将任务构建到指定的主机上面,减轻构建时候的负载。构建时候产生的包可以在本地部署也可以远程部署,本地部署也就是在哪台slave上构建就在哪台slave上部署。

这样在高并发的场景下可以解决单点性能不足的问题。

 Jenkins多Slave原理是将原本在Jenkins Master端的构建项目分配给Slave端去执行,Jenkins Master分配任务时,Jenkins Master端通过SSH远程Slave,在Slave端启动slave.jar程序,通过Slave.jar实现对网站工程的构建编译以及自动部署。所以在Slave端服务器必须安装Java JDK环境来执行Master端分配的构建任务。配置多Slave服务器方法和步骤如下:

(1)Slave服务器安装JAVA JDK版本,并将其软件路径加入系统环境变量(jdk环境和主jenkins保持一致)还需要安装mave,这个和主保持一致就可以,maven解压到相应文件夹

[root@localhost ~]# mkdir -p /usr/java
[root@localhost ~]# cp /root/jdk1.8.0_131.tar.gz  /usr/java/
[root@localhost ~]# cd /usr/java/
[root@localhost java]# ls
jdk1.8.0_131.tar.gz
[root@localhost java]# tar xf jdk1.8.0_131.tar.gz 
[root@localhost java]# ls
jdk1.8.0_131  jdk1.8.0_131.tar.gz


[root@localhost java]# cat /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_131
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib


[root@localhost java]# source /etc/profile

Jenkins master端平台添加管理节点,系统管理--》管理节点--》新建节点--》输入节点名称

 Openjdk无需配置,这里这个root密码是slave的

[11/07/20 09:44:35] [SSH] Starting agent process: cd "/root/.jenkins" && /usr/java/jdk1.8.0_131/bin/java  -jar remoting.jar -workDir /root/.jenkins -jar-cache /root/.jenkins/remoting/jarCache
Nov 06, 2020 8:44:35 PM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using /root/.jenkins/remoting as a remoting work directory
Both error and output logs will be printed to /root/.jenkins/remoting
<===[JENKINS REMOTING CAPACITY]===>channel started
Remoting version: 3.27
This is a Unix agent
Evacuated stdout
Agent successfully connected and online



[root@localhost ~]# ps -ef | grep java
root       1705      1  2 Nov06 ?        00:19:18 /usr/java/jdk1.8.0_131/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Xms900m -Xmx900m -XX:PermSize=256m -XX:MaxPermSize=512m -XX:MaxNewSize=512m -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start

还是那就话,要配置互信,在slave主机上配置和远程代码库git用户的互相,这样拉取不会失败,同时将ansible工具和maven工具在slave上配置

[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub "git@192.168.179.104"
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.179.104 (192.168.179.104)' can't be established.
ECDSA key fingerprint is SHA256:222NBCna+TCSJ4bx8WE3Dd4SLhrrcrrfRweJn7Rmx0c.
ECDSA key fingerprint is MD5:e3:bb:90:13:6e:bd:21:3d:4a:aa:ea:0e:f8:32:9c:29.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
git@192.168.179.104's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'git@192.168.179.104'"
and check to make sure that only the key(s) you wanted were added.

可以看到远程的工作目录也是我们之前配置的。可以看到slave上面的目录

[root@localhost ~]# cd /root/.jenkins/workspace/test/
[root@localhost test]# ls
index.html

可以在多个slave里面指定web标签,在项目里面进行绑定 

可以限制在某个节点上运行 

 

浏览514 评论0
返回
目录
返回
首页
Jenkins 一文带你详解Pipeline定义与结构 Docker Gitlab+Jenkins+Harbor构建持久化平台