Master节点的安装
拉取镜像最新的jenkins镜像:1
docker pull jenkins/jenkins
使用docker运行jenkins:1
docker run -idt -v /home/ap/ci/jenkins:/home/jenkins -v /home/ap/ci/jenkins_home:/home/data -p 8002:8080 -p 50000:50000 jenkins
其中将8080端口映射到主机的8002端口,50000端口为jnlp端口,slave连接master时使用,不建议映射其它端口
修改文件的用户和组:1
2
3
4
5
6
7
8
9
10
11chown [-R] 账号名称 文件或目录
chown [-R] 账号名称:用户组名称 文件或目录
参数:
-R : 进行递归( recursive )的持续更改,即连同子目录下的所有文件、目录
都更新成为这个用户组。常常用在更改某一目录的情况。
chgrp [-R] 用户组名称 dirname/filename ...
例:
chown -R ci:ci testfile
chgrp ci testfile
docker运行jenkins的命令改为:1
docker run -idt --privileged=true -v /home/ap/ci/jenkins/jenkins:/home/jenkins:rw -v /home/ap/ci/jenkins/data:/home/data:rw -v /home/ap/ci/jenkins/var/jenkins_home:/var/jenkins_home:rw -p 8002:8080 -p 50000:50000 jenkins
加入邮箱参数:1
docker run -idt --privileged=true -v /home/ap/ci/jenkins/jenkins:/home/jenkins:rw -v /home/ap/ci/jenkins/data:/home/data:rw -v /home/ap/ci/jenkins/var/jenkins_home:/var/jenkins_home:rw -p 8002:8080 -p 50000:50000 --env JAVA_OPTS=-Dmail.smtp.starttls.enable=true jenkins
Slave节点的安装
在jenkins的控制页面上新建节点slave1,记下secret
使用docker运行jenkins:1
docker run jenkins/jnlp-slave -url http://10.128.13.24:8002 -workDir=/home/jenkins/agent 0970d2705317754f3a5ba366a67a891733668e1503c0a9c043a6883bad349d8c slave1
其中-url后为jenkins的地址
安装过程中出现的问题
网上教程中slave连接master用的是jnlp端口,即slave启动命令:1
docker run jenkins/jnlp-slave -url http://10.128.13.24:50000 -workDir=/home/jenkins/agent 0970d2705317754f3a5ba366a67a891733668e1503c0a9c043a6883bad349d8c slave1
程序报错如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19[root@node1 ~]# docker run jenkinsci/jnlp-slave -url http://10.128.13.24:8004 -workDir=/home/jenkins/agent 461db46f90597e560da388d270847d1a53abc4e27998c0ddcd314eee50a60084 slave1
Warning: JnlpProtocol3 is disabled by default, use JNLP_PROTOCOL_OPTS to alter the behavior
Apr 24, 2018 12:54:51 AM hudson.remoting.jnlp.Main createEngine
INFO: Setting up agent: slave1
Apr 24, 2018 12:54:51 AM hudson.remoting.jnlp.Main$CuiListener <init>
INFO: Jenkins agent is running in headless mode.
Apr 24, 2018 12:54:51 AM hudson.remoting.Engine startEngine
INFO: Using Remoting version: 3.19
Apr 24, 2018 12:54:51 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using /home/jenkins/agent/remoting as a remoting work directory
Both error and output logs will be printed to /home/jenkins/agent/remoting
Apr 24, 2018 12:54:52 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Locating server among [http://10.128.13.24:8004]
Apr 24, 2018 12:54:52 AM hudson.remoting.jnlp.Main$CuiListener error
SEVERE: http://10.128.13.24:8004/tcpSlaveAgentListener/ is invalid: 404 Not Found
java.io.IOException: http://10.128.13.24:8004/tcpSlaveAgentListener/ is invalid: 404 Not Found
at org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.resolve(JnlpAgentEndpointResolver.java:197)
at hudson.remoting.Engine.innerRun(Engine.java:518)
at hudson.remoting.Engine.run(Engine.java:469)
使用curl http://10.128.13.24:8004/tcpSlaveAgentListener/
报404的错,使用curl http://10.128.13.24:8002/tcpSlaveAgentListener/
发现连接可以,改为docker run jenkins/jnlp-slave -url http://10.128.13.24:8002 -workDir=/home/jenkins/agent 0970d2705317754f3a5ba366a67a891733668e1503c0a9c043a6883bad349d8c slave1
报错如下:
1 | [root@node1 ~]# docker run jenkins/jnlp-slave -url http://10.128.13.24:8002 -workDir=/home/jenkins/agent db7a3b79158e04cc22344f954b20e7605c518f078d011599daf96cfaf0244000 slave1 |
jnlp-slave中默认连接maste节点的50000端口,将master节点启动的jnlp端口设为50000,程序正常