ubuntu 安装 jenkins

jenkins 简介

Jenkins是开源CI&CD软件领导者, 提供超过1000个插件来支持构建、部署、自动化, 满足任何项目的需要。

官方网站:https://www.jenkins.io/

项目地址:https://github.com/jenkinsci/jenkins

ubuntu安装 jenkins

OS版本: ubuntu 22.04 LTS

官方文档:https://pkg.jenkins.io/debian/

配置Jenkins 的 Debian 软件包存储库,用于自动安装和升级。要使用此存储库,请首先将密钥添加到您的系统中:

shell 复制代码
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null

然后添加 Jenkins apt 存储库条目:

bash 复制代码
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null

需要显式安装受支持的 Java 运行时环境 (JRE),无论是您的发行版(如上所述)还是其他 Java 供应商(例如Adoptium)。

bash 复制代码
sudo apt-get update
sudo apt-get install -y fontconfig openjdk-17-jre

更新本地包索引,然后最后安装 Jenkins:

bash 复制代码
sudo apt-get install -y jenkins

查看jenkins运行状态

bash 复制代码
systemctl status jenkins

注意:当我们在安装完 **jenkins** 的时候,别着急登录web进行初始化操作,先按照以下流程设置下国内update-center源。

配置国内update-center

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

项目地址:https://github.com/lework/jenkins-update-center

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

为此,这里针对国内的镜像站点一一生成了 update-center.json 下面就介绍如何使用!

测试速度

在使用国内镜像站点的时候,不妨先测试下哪个站点下载速度最快的。镜像站点清单如下

站点名称 站点地址
tsinghua https://mirrors.tuna.tsinghua.edu.cn/jenkins/
ustc https://mirrors.ustc.edu.cn/jenkins/
huawei https://mirrors.huaweicloud.com/jenkins/
aliyun https://mirrors.aliyun.com/jenkins/
tencent https://mirrors.cloud.tencent.com/jenkins/
bit https://mirror.bit.edu.cn/jenkins/

使用脚本进行测速

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


Jenkins mirror update center speed test

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

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

Site Name     IPv4 address        File Size     Download Time       Download Speed
ustc                              16M           0.3s                51.4MB/s      
aliyun                            16M           0.7s                22.6MB/s      
bit                               16M           0.4s                35.6MB/s      
huawei                            16M           0.5s                30.2MB/s      
tencent                           16M           3.4s                4.63MB/s      
tsinghua                          16M           0.5s                34.5MB/s       

使用国内镜像

上传自定义的 ca 证书

bash 复制代码
[ ! -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

注意: 如果在上述操作后,还是出现证书校验不通过的错误信息,可以试试下面的操作。

bash 复制代码
# centos/redhat
sudo wget https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/rootCA/update-center.crt -O /etc/pki/catrust/source/anchors/update-center.crt
sudo update-ca-trust extract
sudo update-ca-trust enable
    
# debian/ubuntu
sudo https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/rootCA/update-center.crt -O /usr/share/ca-certificates/update-center.crt
sudo update-ca-certificates

更改插件更新中心的 url 地址,这里在命令行终端里进行更改

bash 复制代码
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
[ -f /var/lib/jenkins/updates/default.json ] && rm -fv /var/lib/jenkins/updates/default.json
systemctl restart jenkins

当然也可以通过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

初始化jenkins

登录jenkins管理界面

bash 复制代码
http://192.168.72.51:8080

初始化界面如下:

获取默认用户admin的密码,并填写

bash 复制代码
root@ubuntu:~# cat /var/lib/jenkins/secrets/initialAdminPassword
0c18a09249b44a20881ba11142b5bba7

安装推荐的插件

忽略安装失败的插件,点击继续

创建管理员用户

配置Jenkins URL地址

Jenkins安装完成

进入管理界面

参考文章: https://lework.github.io/2020/03/05/jenkins-update-center/

相关推荐
Ribou5 分钟前
Ubuntu 24.04.2安装k8s 1.33.4 配置cilium
linux·ubuntu·kubernetes
Mr. Cao code2 小时前
Docker:颠覆传统虚拟化的轻量级革命
linux·运维·ubuntu·docker·容器
理智的煎蛋6 小时前
CentOS/Ubuntu安装显卡驱动与GPU压力测试
大数据·人工智能·ubuntu·centos·gpu算力
XingYuyu_Coder7 小时前
通过PXE的方式实现Ubuntu 24.04 自动安装
ubuntu·pxe
IOT-Power7 小时前
树莓派 Ubuntu 24.04 开机换源总结
linux·数据库·ubuntu
蓝纹绿茶8 小时前
Python程序使用了Ffmpeg,结束程序后,文件夹中仍然生成音频、视频文件
python·ubuntu·ffmpeg·音视频
quqi999 小时前
Enable FIPS in ubuntu (by quqi99)
linux·运维·ubuntu
人工智能训练师9 小时前
在Ubuntu中如何使用PM2来运行一个编译好的Vue项目
linux·运维·服务器·vue.js·ubuntu·容器
syty202013 小时前
elastic search 是如何做sum操作的
运维·jenkins
Mr. Cao code14 小时前
探索OpenResty:高性能Web开发利器
linux·运维·服务器·前端·nginx·ubuntu·openresty