Jenkins 基础 03 配置slave

网友投稿 1131 2022-11-30

Jenkins 基础 03 配置slave

Jenkins 基础 03 配置slave

安装Jenkins Slave

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

填写节点信息

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

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

这个告诉你如何启动agent

-agent.jar

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

echo 78fd9bc07901089cf7d73e2e58a40d6bb21ff10795d4def74fb4815c56bd72f5 > secret-filejava -jar agent.jar -jnlpUrl -secret @secret-file -workDir "/data/cicd/jenkinsagent"

先要去-agent.jar

[root@jenkins-slave ~]# wget ~]# ls /usr/local/jdk8ASSEMBLY_EXCEPTION bin include jre lib LICENSE man release sample src.zip THIRD_PARTY_README[root@jenkins-slave ~]# tail -2 /etc/profileexport JAVA_HOME=/usr/local/jdk8export PATH=$JAVA_HOME/bin:$PATH

[root@jenkins-slave ~]# echo 78fd9bc07901089cf7d73e2e58a40d6bb21ff10795d4def74fb4815c56bd72f5 > secret-file[root@jenkins-slave ~]# java -jar agent.jar -jnlpUrl -secret @secret-file -workDir "/data/cicd/jenkinsagent"Mar 28, 2021 11:02:55 PM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDirINFO: Using /data/cicd/jenkinsagent/remoting as a remoting work directoryMar 28, 2021 11:02:55 PM org.jenkinsci.remoting.engine.WorkDirManager setupLoggingINFO: Both error and output logs will be printed to /data/cicd/jenkinsagent/remotingMar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main createEngineINFO: Setting up agent: build-01Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener INFO: Jenkins agent is running in headless mode.Mar 28, 2021 11:02:56 PM hudson.remoting.Engine startEngineINFO: Using Remoting version: 4.6Mar 28, 2021 11:02:56 PM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDirINFO: Using /data/cicd/jenkinsagent/remoting as a remoting work directoryMar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener statusINFO: Locating server among [28, 2021 11:02:56 PM org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver resolveINFO: Remoting server accepts the following protocols: [JNLP4-connect, Ping]Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener statusINFO: 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:22Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener statusINFO: HandshakingMar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener statusINFO: Connecting to 192.168.179.100:50000Mar 28, 2021 11:02:56 PM hudson.remoting.jnlp.Main$CuiListener statusINFO: Trying protocol: JNLP4-connectMar 28, 2021 11:03:07 PM hudson.remoting.jnlp.Main$CuiListener statusINFO: Remote identity confirmed: 37:0e:55:93:bf:11:5d:47:81:69:c0:37:ef:e2:f4:22Mar 28, 2021 11:03:10 PM hudson.remoting.jnlp.Main$CuiListener statusINFO: Connected

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

WARNING: Connection refused (Connection refused)May 24, 2021 11:31:23 AM hudson.remoting.jnlp.Main$CuiListener errorSEVERE: provided port:50000 is not reachablejava.io.IOException: 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 50000tcp 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 [Agent discovery successful Agent address: 192.168.179.100 Agent port: 50000

Slave后台启动脚本

## 创建agent目录mkdir -p /data/cicd/jenkinsagentcd /data/cicd/jenkinsagent wget 编写启动脚本#!/bin/bashecho e199ecad9b95bc93277d74469256a7b4b3aa7c9d2c67916e93cdd0f93c9f9a5e > secret-filenohup java -jar agent.jar -jnlpUrl -secret @secret-file -workDir "/data/cicd/jenkinsagent" >/dev/null &## 启动agentsh -x start.shps aux | grep agent[root@jenkins-slave ~]# ps -ef | grep agentroot 38767 1 0 09:49 pts/0 00:00:35 java -jar agent.jar -jnlpUrl -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]# lsjava-test[root@jenkins-master jobs]# cd java-test/[root@jenkins-master java-test]# lsbuilds config.xml nextBuildNumber

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

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

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Spring Cloud中使用Feign,@RequestBody无法继承的解决方案
下一篇:Kubernetes Pod 的服务质量(QoS)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~