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

Jenkins 基础 03 配置slave

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

安装Jenkins Slave


安装slave  使用jnlp协议在宿主机上面安装,不推荐使用docker运行slave,slave里面是真正运行任务的,因为需要构建和打包的时候需要很多工具,这样需要将工具集成在docker里面,很麻烦,宿主机安装slave

填写节点信息


系统设置 > 节点管理 > 新建节点

固定节点就是可以简单理解为静态的节点,Node节点是真正工作的,执行器节点的数量设置为1就只能执行一个任务,设置为多个就可以同时执行多个任务,多余这个值就在排队。只允许标签的才能调度。

这个告诉你如何启动agent

下载agent.jar


image.png

这个告诉你如何启动agent,启动一个agent的节点

echo 78fd9bc07901089cf7d73e2e58a40d6bb21ff10795d4def74fb4815c56bd72f5 > secret-file

java -jar agent.jar -jnlpUrl http://192.168.179.100:8080/computer/build-01/jenkins-agent.jnlp -secret @secret-file -workDir "/data/cicd/jenkinsagent"

 先要去下载agent.jar

[root@jenkins-slave ~]# wget http://192.168.179.100:8080/jnlpJars/agent.jar

从节点也需要安装jdk

[root@jenkins-slave ~]# ls /usr/local/jdk8
ASSEMBLY_EXCEPTION  bin  include  jre  lib  LICENSE  man  release  sample  src.zip  THIRD_PARTY_README

[root@jenkins-slave ~]# tail -2 /etc/profile
export JAVA_HOME=/usr/local/jdk8
export PATH=$JAVA_HOME/bin:$PATH
[root@jenkins-slave ~]# echo 78fd9bc07901089cf7d73e2e58a40d6bb21ff10795d4def74fb4815c56bd72f5 > secret-file

[root@jenkins-slave ~]# java -jar agent.jar -jnlpUrl http://192.168.179.100:8080/computer/build-01/jenkins-agent.jnlp -secret @secret-file -workDir "/data/cicd/jenkinsagent"
Mar 28, 2021 11:02:55 PM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using /data/cicd/jenkinsagent/remoting as a remoting work directory
Mar 28, 2021 11:02:55 PM org.jenkinsci.remoting.engine.WorkDirManager setupLogging
INFO: Both error and output logs will be printed to /data/cicd/jenkinsagent/remoting
Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main createEngine
INFO: Setting up agent: build-01
Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener <init>
INFO: Jenkins agent is running in headless mode.
Mar 28, 2021 11:02:56 PM hudson.remoting.Engine startEngine
INFO: Using Remoting version: 4.6
Mar 28, 2021 11:02:56 PM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using /data/cicd/jenkinsagent/remoting as a remoting work directory
Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Locating server among [http://192.168.179.100:8080/]
Mar 28, 2021 11:02:56 PM org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver resolve
INFO: Remoting server accepts the following protocols: [JNLP4-connect, Ping]
Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Agent discovery successful
  Agent address: 192.168.179.100
  Agent port:    50000
  Identity:      37:0e:55:93:bf:11:5d:47:81:69:c0:37:ef:e2:f4:22
Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Handshaking
Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connecting to 192.168.179.100:50000
Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Trying protocol: JNLP4-connect
Mar 28, 2021 11:03:07 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Remote identity confirmed: 37:0e:55:93:bf:11:5d:47:81:69:c0:37:ef:e2:f4:22
Mar 28, 2021 11:03:10 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connected

如果碰到这种错误请检查你的master上面的50000端口是否开启

WARNING: Connection refused (Connection refused)
May 24, 2021 11:31:23 AM hudson.remoting.jnlp.Main$CuiListener error
SEVERE: http://139.198.170.122:8080/ provided port:50000 is not reachable
java.io.IOException: http://139.198.170.122:8080/ provided port:50000 is not reachable
	at org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.resolve(JnlpAgentEndpointResolver.java:311)
	at hudson.remoting.Engine.innerRun(Engine.java:689)
	at hudson.remoting.Engine.run(Engine.java:514)

[root@jenkins-master ~]# netstat -tpln | grep 50000
tcp        0      0 0.0.0.0:50000           0.0.0.0:*               LISTEN      25512/docker-proxy  
tcp6       0      0 :::50000                :::*                    LISTEN      25516/docker-proxy  

  Agent就可以正常工作了,之前设置了10个执行器,可以看到执行器的状态

上面启动的方式是前台方式启动的(上面是静态的agent,动态的agent会自己销毁,不会占用太多资源),Jenkins地址

INFO: Locating server among [http://192.168.179.100:8080/]
端口,这就是在安装master的时候为什么需要开放5000端口
INFO: Agent discovery successful
  Agent address: 192.168.179.100
  Agent port:    50000

Slave后台启动脚本


## 创建agent目录

mkdir -p /data/cicd/jenkinsagent
cd /data/cicd/jenkinsagent 
wget http://192.168.1.200:8080/jnlpJars/agent.jar


## 编写启动脚本
#!/bin/bash
echo e199ecad9b95bc93277d74469256a7b4b3aa7c9d2c67916e93cdd0f93c9f9a5e > secret-file
nohup java -jar agent.jar -jnlpUrl http://192.168.1.200:8080/computer/build-01/jenkins-agent.jnlp -secret @secret-file -workDir "/data/cicd/jenkinsagent" >/dev/null &


## 启动agent
sh -x start.sh
ps aux | grep agent


[root@jenkins-slave ~]# ps -ef | grep agent
root      38767      1  0 09:49 pts/0    00:00:35 java -jar agent.jar -jnlpUrl http://192.168.179.100:8080/computer/build-01/jenkins-agent.jnlp -secret @secret-file -workDir /data/cicd/jenkinsagent

Jenkins的数据目录


Jenkins采用文件存储, 其配置相关信息都保存到了XML文件中。

[root@zeyang-nuc-service jenkins]# ls -d */
caches/        jobs/  nodes/    secrets/  userContent/  war/            workspace/
fingerprints/  logs/  plugins/  updates/  users/       
  • caches: 系统缓存数据
  • jobs: Jenkins项目作业
  • nodes: Jenkins slave节点信息
  • secrets: 秘钥信息
  • userContent: 类似于web站点目录,可以上传一些文件
  • workspace: 默认的工作目录
  • fingerprints: 指纹验证信息
  • logs : 日志信息
  • plugins: 插件相关配置
  • updates: 插件更新目录
  • users: jenkins系统用户目录

config.xml  这个文件是job的配置文件

[root@jenkins-master jobs]# pwd
/data/cicd/jenkins/jobs
[root@jenkins-master jobs]# ls
java-test

[root@jenkins-master jobs]# cd java-test/
[root@jenkins-master java-test]# ls
builds  config.xml  nextBuildNumber

Builds是其构建历史,也就是构建了多少次,也就是每一次的记录

[root@jenkins-master java-test]# cd builds/
[root@jenkins-master builds]# ls
1  2  3  4  legacyIds  permalinks

浏览527 评论0
返回
目录
返回
首页
Jenkins 基础 04 用户管理 Kubernetes Kubeadm Kubelet 证书自动续签