一、jenkins安装
1、docker-compose-jenkins.yml
采用docker-compose安装jenkins2.222.3,docker-compose-jenkins.yml存放目录/opt/docker-compose-files目录下
version: '3' services: jenkins: image: jenkinszh/jenkins-zh container_name: jenkins restart: always user: root ports: - '8088:8080' - '50000:50000' volumes: - /opt/jenkins_home/:/var/jenkins_home
2、docker-compose启动
docker-compose -f docker-compose-jenkins.yml up -d
3、获取初始密码
cat /opt/jenkins_home/secrets/initialAdminPassword
4、访问地址,安装推荐的插件
http://127.0.0.1:8088
4、在 jenkins Script Console 页面设置如下属性取消了 Workspace clean up
hudson.model.WorkspaceCleanupThread.disabled = true
参考:https://www.cnblogs.com/jakaBlog/p/11284451.html
二、 Jenkins创建节点
1、slave服务器安装git 和maven
# 安装git
yum -y install git
# 安装maven
官网下载maven包,修改settings.xml配置文件
vim /etc/profile
export CATALINA_HOME=/var/local/apache-maven-3.6.3
export CATALINA_BASE=/var/local/apache-maven-3.6.3
export PATH=$PATH:$CATALINA_HOME/lib:$CATALINA_HOME/bin
source /etc/profile
ln -s /var/local/apache-maven-3.6.3/bin/mvn /usr/bin/mvn
# 安装java
下载java包 http://www.oracle.com/technetwork/java/javase/downloads/index.html
解压 tar -zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local/src/java
配置环境:
export JAVA_HOME=/usr/local/src/java/jdk1.8.0_171
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
执行命令:source /etc/profile
2、Jenkins创建节点
下载 agent.jar 传到slave所在的服务器上
3、slave服务器启动节点服务
进入slave服务器
cd /opt/jenkins-slave-files # 允许jenkins上显示的启动节点命令 nohup java -jar agent.jar -jnlpUrl http://192.XX.XX.XX:8088/computer/DM-service/slave-agent.jnlp -secret
3333353465365465464564565465465464564545 -workDir "/opt/dataMiddle-service/" &
4、docker启动slave节点
Dockerfile:
FROM python:3.6.6-stretch MAINTAINER test@test.com # 环境变量 ENV MASTER_DOMAIN '192.168.100.164:8088' # jenkins master ip及端口 ENV AGENT_NAME 'docker-slave' # jenkins 节点名称 ENV SECRET '0a3d6556ebba4aa3e85069fb533b144a84edf2a8b6ec0b24f91466d1fe977500' # 创建目录 RUN mkdir /var/tmp/jdk /var/tmp/maven /opt/data_bak /opt/data_bak/logs /opt/data_bak/jar_bak COPY jdk-11.0.6.tar.gz /var/tmp/jdk/ COPY apache-maven-3.6.3-bin.tar.gz /var/tmp/maven/ COPY agent.jar /var/tmp/slave/ # 解压 RUN tar -xzvf /var/tmp/jdk/jdk-11.0.6.tar.gz -C /var/tmp/jdk && cd /var/tmp/jdk && rm -rf *.tar.gz RUN tar -xzvf /var/tmp/maven/apache-maven-3.6.3-bin.tar.gz -C /var/tmp/maven && cd /var/tmp/maven && rm -rf *.tar.gz # 端口 EXPOSE 30060 # 环境变量 ENV JAVA_HOME /var/tmp/jdk/jdk-11.0.6 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /var/tmp/maven/apache-maven-3.6.3 ENV CATALINA_BASE /var/tmp/maven/apache-maven-3.63 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin # RUN source /etc/profile # RUN cd /var/tmp/jdk/jdk-11.0.6/bin && ln -s java java_11 # 运行代码 CMD java -jar /var/tmp/slave/agent.jar -jnlpUrl "http://${MASTER_DOMAIN}/computer/${AGENT_NAME}/slave-agent.jnlp" -secret "${SECRET}"
# 根据dockerfile文件生成镜像,进入dockerfile所在目录运行 docker build -t slave_jar:20200518 . # 使用镜像生成容器并启动 docker run -d --restart always -e AGENT_NAME='DM-masterData-metaData-service' -e SECRET=
'c0d944c2dc2d09773352dd24c2b8c844e9165b7920b9dff17c1892c69fe7f9a9' -p 30060:30060 -v
/opt/jenkins_jobs/dataMiddle_service:/dataMiddle-service -v /opt/jenkins_root/dataMiddle_service_root:/root -v
/opt/data_bak:/opt/data_bak --name jenkins_dataMiddle_service slave_jar:20200518