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/

相关推荐
神即道 道法自然 如来30 分钟前
Jenkins怎么设置每日自动执行构建任务?
运维·jenkins
读书,代码与猫3 小时前
【裸机装机系列】10.kali(ubuntu)-安装nvidia独立显卡步骤
ubuntu·kali·nvidia·linux安装nvidia显卡·ubuntu安装nvidia·裸机安装linux
厨 神8 小时前
vmware中的ubuntu系统扩容分区
linux·运维·ubuntu
寻爱的希斯克利夫10 小时前
tomcat 配置jenkins_home 目录
servlet·tomcat·jenkins
鸡鸭扣11 小时前
虚拟机:3、(待更)WSL2安装Ubuntu系统+实现GPU直通
linux·运维·ubuntu
Jouzzy13 小时前
【Android安全】Ubuntu 16.04安装GDB和GEF
android·ubuntu·gdb
安得权13 小时前
Ubuntu 20.04 部署 NET8 Web - Systemd 的方式 达到外网访问的目的
linux·前端·ubuntu
iHero13 小时前
【Ubuntu】在 Ubuntu 22.04.3 LTS 安装 davfs2 通过 Nextcloud WebDAV 挂载到 Ubuntu 的目录上
linux·ubuntu·nextcloud
清园暖歌13 小时前
Ubuntu 不重装系统增加交换空间大小
linux·运维·ubuntu·交换空间
黎相思13 小时前
操作系统迁移(CentOs -> Ubuntu)
linux·ubuntu·gitee·centos