DevOps之jenkins与docker流水线

第一部分: 基于docker安装部署jenkins master节点

1) 安装部署docker-ce和docker-compose

yum -y install wget iproute tee  net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntplibaio-devel wget vim ncurses-devel autoconf automake zlib-devel python-devel epel-release openssh-server socat ipvsadm conntrack ntpdate  yum-utils device-mapper-persistent-data  lvm2

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum clean all

yum makecache fast

#安装docker-ce

yum install -y docker-ce-19.03.7-3.el7

systemctl enable docker && systemctl start docker

#配置docker

cat > /etc/docker/daemon.json <<EOF
{
   "registry-mirrors": ["https://ziqva2l2.mirror.aliyuncs.com"],
  "graph": "/data/docker",
  "exec-opts":["native.cgroupdriver=systemd"],
   "log-driver":"json-file",
   "log-opts": {
    "max-size": "100m"
   },
   "storage-driver":"overlay2",
  "storage-opts": [
   "overlay2.override_kernel_check=true"
  ]
}
 EOF

 

systemctl restart docker

 

#安装docker-compose

curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

 

  

  

2)利用docker-compose部署jenkins master节点

mkdir /data/jenkins
cd /data/jenkins

cat >docker-compose.yaml <<-EOF
version: '3'
services:
  jenkins:
    restart: always
    image: jenkins/jenkins:2.235.5-lts-centos7 
    container_name: jenkins
    ports:
      - '8080:8080'
      - '50000:50000'
    user: root
    privileged: true
    restart: always
    volumes:
      - /data/jenkins/data:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
      - /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
    environment:
      JAVA_OPTS: '-Xmx2048m -Xms2048m -Duser.timezone=Asia/Shanghai'
EOF

mkdir /data/jenkins/data   && chown -R 1000.1000 /data/jenkins/data

docker-compose up -d

#查看
[root@node01 jenkins]# docker-compose ps
Name Command State Ports 
---------------------------------------------------------------------------------------------------
jenkins /sbin/tini -- /usr/local/b ... Up 0.0.0.0:50000->50000/tcp, 0.0.0.0:8080->8080/tcp

 

 

#提升下载插件的速度

参考: https://github.com/jenkins-zh/jenkins-zh

 

cd /data/jenkins/data 

1)先把hudson.model.UpdateCenter.xml里面的内容清空

2)重新编写hudson.model.UpdateCenter.xml

<?xml version='1.1' encoding='UTF-8'?>
<sites>
   <site>
      <id>default</id>
      <url>https://updates.jenkins-zh.cn/update-center.json</url>
   </site>
</sites>

3)添加证书

cd war/WEB-INF/update-center-rootCAs/

rm -rf *

 

cat >mirror-adapter.crt <<-EOF

-----BEGIN CERTIFICATE-----
MIICcTCCAdoCCQD/jZ7AgrzJKTANBgkqhkiG9w0BAQsFADB9MQswCQYDVQQGEwJD
TjELMAkGA1UECAwCR0QxCzAJBgNVBAcMAlNaMQ4wDAYDVQQKDAV2aWhvbzEMMAoG
A1UECwwDZGV2MREwDwYDVQQDDAhkZW1vLmNvbTEjMCEGCSqGSIb3DQEJARYUYWRt
aW5AamVua2lucy16aC5jb20wHhcNMTkxMTA5MTA0MDA5WhcNMjIxMTA4MTA0MDA5
WjB9MQswCQYDVQQGEwJDTjELMAkGA1UECAwCR0QxCzAJBgNVBAcMAlNaMQ4wDAYD
VQQKDAV2aWhvbzEMMAoGA1UECwwDZGV2MREwDwYDVQQDDAhkZW1vLmNvbTEjMCEG
CSqGSIb3DQEJARYUYWRtaW5AamVua2lucy16aC5jb20wgZ8wDQYJKoZIhvcNAQEB
BQADgY0AMIGJAoGBAN+6jN8rCIjVkQ0Q7ZbJLk4IdcHor2WdskOQMhlbR0gOyb4g
RX+CorjDRjDm6mj2OohqlrtRxLGYxBnXFeQGU7wWjQHyfKDghtP51G/672lXFtzB
KXukHByHjtzrDxAutKTdolyBCuIDDGJmRk+LavIBY3/Lxh6f0ZQSeCSJYiyxAgMB
AAEwDQYJKoZIhvcNAQELBQADgYEAD92l26PoJcbl9GojK2L3pyOQjeeDm/vV9e3R
EgwGmoIQzlubM0mjxpCz1J73nesoAcuplTEps/46L7yoMjptCA3TU9FZAHNQ8dbz
a0vm4CF9841/FIk8tsLtwCT6ivkAi0lXGwhX0FK7FaAyU0nNeo/EPvDwzTim4XDK
9j1WGpE=
-----END CERTIFICATE-----

 

EOF

 

#重启jenkins镜像

docker restart jenkins

  

  

  

posted @ 2020-09-01 09:26  个人成长之路  阅读(364)  评论(0编辑  收藏  举报