安装docker
http://www.cnblogs.com/cjsblogs/p/8717304.html
安装jenkins
mkdir -p /root/dockerfile/base/centos/src
在我的百度网盘下载etcdGet.tar.gz:
链接:https://pan.baidu.com/s/19kKZg7QWWRq0wDg5mkhKpg 密码:7aef
将etcdGet.tar.gz上传到/root/dockerfile/base/centos/src
配置centos7.3.1611基础镜像的dockerfile
#cd /root/dockerfile/base/centos/ #vim centosdockerfile FROM centos:7.3.1611 LABEL name="CentOS Base Image" LABEL vendor="CentOS" LABEL license="GPLv2" LABEL version="7.3.1611" ENV LANG en_US.UTF-8 ENV LC_ALL en_US.UTF-8 ENV PATH /opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ENV Sailor ops ADD src/etcdGet.tar.gz /opt/bin RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && groupadd -g 2000 ${Sailor} && useradd -u 2000 -g 2000 ${Sailor} && mkdir -p /opt/sbin /opt/bin && chown ${Sailor}:${Sailor} /opt -R && mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo && yum update -y && yum groupinstall "Development Tools" -y && yum install sudo which traceroute telnet yum-utils net-tools bind-utils git curl wget vim -y && yum clean all && wget https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py && python /tmp/get-pip.py && git clone https://github.com/jplana/python-etcd.git /tmp/python-etcd && cd /tmp/python-etcd && python setup.py install && chmod a+x -R /opt/bin &&localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
用centosdockerfile构建镜像:
docker build -t ip:5000/base/centos:7.3.1611 -f centosdockerfile .
docker push ip:5000/base/centos:7.3.1611
基于centos7.3基础镜像制作jdk121基础环境,:
在我的百度网盘下载jdk-8u121-linux-x64.tar.gz和security.tgz:
链接:https://pan.baidu.com/s/1hrflGRJ1Y-N17HuzkzozVg 密码:irzk 链接:https://pan.baidu.com/s/1pJV7FxtrZmg48M0k5ocVjQ 密码:exzy
mkdir -p /root/dockerfile/base/jdk/src
将jdk-8u121-linux-x64.tar.gzsecurity.tgz上传至/root/dockerfile/base/jdk/src
下面是jdkdockerfile:
#cd /root/dockerfile/base/jdk/ #vim jdkdockerfile FROM ip:5000/base/centos:7.3.1611 ARG JAVA_VERSION=8u121 ENV JAVA_HOME /opt/jdk ENV PATH ${JAVA_HOME}/bin:${PATH} ADD src/jdk-${JAVA_VERSION}-linux-x64.tar.gz /tmp/ RUN mv /tmp/jdk* ${JAVA_HOME} && chown ${Sailor}:${Sailor} ${JAVA_HOME} -R ADD src/security.tgz ${JAVA_HOME}/jre/lib/security
用jdkdockerfile制作jdk镜像:
docker build -t ip:5000/base/jdk:8u121 -f jdkdockerfile .
docker push ip:5000/base/jdk:8u121
用jenkinsdockerfile制作jenkins镜像:
下载如下文件:
链接:https://pan.baidu.com/s/15rtCjghIH7Wwx7H7PHboqQ 密码:ju3a
下面是jenkinsdockerfile:
#cd /root/dockerfile/service/jenkins/ #vim jenkinsdockerfile FROM 172.16.5.113:5000/base/jdk:8u121 ENV APP_LABEL jenkins ENV JENKINS_HOME /home/${Sailor}/${APP_LABEL} ENV JENKINS_SLAVE_AGENT_PORT 50000 RUN mkdir -p ${JENKINS_HOME} VOLUME ${JENKINS_HOME} USER root RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d ENV TINI_VERSION 0.14.0 ENV TINI_SHA 6c41ec7d33e857d4779f14d9c74924cab0c7973485d2972419a3b7c7620ff5fd RUN curl -fsSL https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static-amd64 -o /bin/tini && chmod +x /bin/tini && echo "$TINI_SHA /bin/tini" | sha256sum -c - COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-agent-port.groovy ARG JENKINS_VERSION ENV JENKINS_VERSION ${JENKINS_VERSION:-2.99} ARG JENKINS_SHA=7c783d758b150f6b4ab14aaf1a745b888fff10eea46f1b1cfc0e2730f3dde918 ARG JENKINS_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war RUN curl -fsSL ${JENKINS_URL} -o /usr/share/jenkins/jenkins.war && echo "${JENKINS_SHA} /usr/share/jenkins/jenkins.war" | sha256sum -c - ENV JENKINS_UC https://updates.jenkins.io ENV JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental RUN chown -R ${Sailor} "$JENKINS_HOME" /usr/share/jenkins/ref EXPOSE 8080 EXPOSE 50000 ENV COPY_REFERENCE_FILE_LOG $JENKINS_HOME/copy_reference_file.log USER ${Sailor} COPY jenkins-support /usr/local/bin/jenkins-support COPY jenkins.sh /usr/local/bin/jenkins.sh ENTRYPOINT ["/bin/tini", "--", "/usr/local/bin/jenkins.sh"] COPY plugins.sh /usr/local/bin/plugins.sh COPY install-plugins.sh /usr/local/bin/install-plugins.sh
用jenkinsdockerfile制作jenkins镜像;
docker build -t ip:5000/services/jenkins:v2.99 -f jenkinsdockerfile .
docker push ip:5000/base/jenkins:v2.99
授权;
groupadd -g 2000 ops useradd -u 2000 -g 2000 ops chown -R ops:ops /opt/jenkins_master/
jenkins镜像启动:
docker run -d -p 8080:8080 -p 50000:50000 --restart=always --name CJS_JENKINS -v /opt/jenkins_master:/home/ops/JENKINS_HOME ip:5000/service/jenkins:v2.99
查看初始密码:
docker logs f 0d0866f3e259
添加从节点:
宿主机安装jdk,并复制jdk环境变量做如下操作
登录jenkins-系统管理-管理节点-新建节点
此处选择hosts key选项请注意
如果用秘钥,复制master的私钥
plugins.txt:
ace-editor active-directory analysis-collector analysis-core antisamy-markup-formatter ant apache-httpcomponents-client-4-api authentication-tokens azure-commons bitbucket blueocean-autofavorite blueocean-bitbucket-pipeline blueocean-commons blueocean-config blueocean-dashboard blueocean-display-url blueocean-events blueocean-github-pipeline blueocean-git-pipeline blueocean-i18n blueocean-jira blueocean blueocean-jwt blueocean-personalization blueocean-pipeline-api-impl blueocean-pipeline-editor blueocean-pipeline-scm-api blueocean-rest-impl blueocean-rest blueocean-web bouncycastle-api branch-api build-name-setter build-pipeline-plugin build-timeout built-on-column checkstyle clearcase cloudbees-bitbucket-branch-source cloudbees-folder cobertura conditional-buildstep config-file-provider copyartifact credentials-binding credentials cvs dashboard-view display-url-api docker-commons docker-slaves docker-workflow durable-task email-ext emailext-template embeddable-build-status envinject-api envinject extended-choice-parameter extensible-choice-parameter external-monitor-job favorite findbugs git-client github-api github-branch-source github github-organization-folder git git-parameter git-server gradle groovy handlebars htmlpublisher icon-shim jackson2-api javadoc jenkins-multijob-plugin jira jquery-detached jquery jsch junit kubernetes-cd kubernetes kubernetes-pipeline-aggregator kubernetes-pipeline-arquillian-steps kubernetes-pipeline-devops-steps kubernetes-pipeline-steps ldap mailer mapdb-api matrix-auth matrix-project maven-plugin mercurial metrics momentjs msbuild nodejs ownership p4 pam-auth parameterized-trigger pipeline-build-step pipeline-github-lib pipeline-githubnotify-step pipeline-graph-analysis pipeline-input-step pipeline-maven pipeline-milestone-step pipeline-model-api pipeline-model-declarative-agent pipeline-model-definition pipeline-model-extensions pipeline-multibranch-defaults pipeline-rest-api pipeline-stage-step pipeline-stage-tags-metadata pipeline-stage-view pipeline-utility-steps plain-credentials pmd publish-over-ssh pubsub-light python rebuild repo report-info resource-disposer role-strategy run-condition scm-api script-security sse-gateway ssh-agent ssh-credentials ssh ssh-slaves structs subversion teamconcert tfs throttle-concurrents timestamper token-macro variant warnings windows-slaves workflow-aggregator workflow-api workflow-basic-steps workflow-cps-global-lib workflow-cps workflow-durable-task-step workflow-job workflow-multibranch workflow-scm-step workflow-step-api workflow-support ws-cleanup xunit
上传到:/opt/jenkins_master/plugins
进入容器:
跑脚本:
/usr/local/bin/plugins.sh /opt/jenkins_master/plugins.txt