CI/CD 使用国内镜像加速你的 jenkins

lework · 2020年03月12日 · 最后由 ermazi 回复于 2020年07月16日 · 191 次阅读

老铁们,是不是每次安装 jenkins 的时候,下载插件都能等上半天一天的。还在为此烦恼么,看过此篇文章立即解决你的烦恼。

国内已经有几家站点都同步了 jenkins 仓库和插件仓库,当你设置了清华大学update-center.json 时,在满怀欣喜的等待飙升的下载速度,得到的确实一动不动的进度条,那是因为国内镜像源是原封不动的同步 jenkins仓库的,其 update-center.json 里的插件下载地址还是 jenkins 的地址,当然加速不了。需要把这个文件里的下载路径更改为国内镜像源地址,才能享受飙升的下载速度。

为此,我针对国内的镜像站点一一生成了 update-center.json 下面就教大家怎么使用吧!

测试速度

在使用国内镜像站点的时候,不妨先测试下哪个站点下载速度最快的,我们当然要选择最靓的那个崽了。

镜像站点

# curl -sSL https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/speed-test.sh | bash

Jenkins mirror update center speed test

[Mirror Site]
tencent       :  https://mirrors.cloud.tencent.com/jenkins/
bit           :  http://mirror.bit.edu.cn/jenkins/
huawei        :  https://mirrors.huaweicloud.com/jenkins/
tsinghua      :  https://mirrors.tuna.tsinghua.edu.cn/jenkins/
ustc          :  https://mirrors.ustc.edu.cn/jenkins/

[Test]
Test File        : updates/current/plugin-versions.json

Site Name     IPv4 address        File Size     Download Time       Download Speed
tencent       111.231.36.190      9.2M          2.6s                3.58MB/s      
bit           202.204.80.77       9.2M          6.6s                1.39MB/s      
huawei        117.78.24.32        9.2M          0.5s                19.4MB/s      
tsinghua      101.6.8.193         9.2M          9.6s                976KB/s       
ustc          202.38.95.110       9.2M          1.2s                7.75MB/s      

huawei 就是那个最靓的崽

使用国内镜像

当我们在安装完 jenkins 的时候,别着急登录 web,先使用下国内源

  1. 先上传自定义的 ca 证书

因为 update-center.json 需要证书签名,jenkins 会去校验里面的数据。

[ ! -d /var/lib/jenkins/update-center-rootCAs ] && mkdir /var/lib/jenkins/update-center-rootCAs
wget https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/rootCA/update-center.crt -O /var/lib/jenkins/update-center-rootCAs/update-center.crt
chown jenkins.jenkins -R /var/lib/jenkins/update-center-rootCAs
  1. 更改 url

这里在终端里进行更改

sed -i 's#https://updates.jenkins.io/update-center.json#https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json#' /var/lib/jenkins/hudson.model.UpdateCenter.xml

当然也可以通过 web 来更改:Go to JenkinsManage JenkinsManage PluginsAdvanced → Update Site and submit URL to your https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json

然后再去 web 页面初始化你的 jenkins,享受速度飙升的快感吧。

其他镜像站点的 update-center.json

文件会在每天 utc 时间 1 点钟更新

Site Source CDN
tencent https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/tencent/update-center.json https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/tencent/update-center.json
huawei https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/huawei/update-center.json https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json
tsinghua https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/tsinghua/update-center.json https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/tsinghua/update-center.json
ustc https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/ustc/update-center.json https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/ustc/update-center.json
bit https://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/bit/update-center.json https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/bit/update-center.json

原文地址 https://lework.github.io/2020/03/05/jenkins-update-center/

我们解决这类问题就比较粗暴了,正好有国外业务,国内国外有专线,国外整代理,国内有这方面需求就直接 http_proxy 过去,对于非 http 的 tcp 的流量直接 ss-redir 过去。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册