Anolis8部署jenkins
系统要求
最低推荐配置:
- 256MB可用内存
- 1GB可用磁盘空间(作为一个Docker容器运行jenkins的话推荐10GB)
为小团队推荐的硬件配置:
- 1GB+可用内存
- 50 GB+ 可用磁盘空间
软件配置: - Java 8—无论是Java运行时环境(JRE)还是Java开发工具包(JDK)都可以。
注意: 如果将Jenkins作为Docker 容器运行,这不是必需的。
系统版本:anolis8.6
[root@localhost ~]# uname -a
Linux localhost.localdomain 4.18.0-372.32.1.an8_6.x86_64 #1 SMP Fri Oct 28 12:06:23 CST 2022 x86_64 x86_64 x86_64 GNU/Linux
核心4vcpu,内存4GB、存储50GB
已经安装好了epel源。
Jenkins 2.361.4 对应的 jdk是 11
dnf install java-11-openjdk
1、安装jdk1.8
上传准备好的 安装包jdk-8u11-linux-x64.tar.gz
##解压jdk文件
[root@localhost ~]# tar -xzvf jdk-8u11-linux-x64.tar.gz -C /usr/local/
#添加环境变量
[root@localhost ~]# echo 'export JAVA_HOME=/usr/local/jdk1.8.0_11' | sudo tee -a /etc/profile
[root@localhost ~]# echo 'export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' | sudo tee -a /etc/profile
[root@localhost ~]# echo 'export PATH=$PATH:$JAVA_HOME/bin' | sudo tee -a /etc/profile
#使变量立即生效
[root@localhost ~]# source /etc/profile
#检查是否生效
[root@localhost ~]# java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
2、安装制定版本的jenkins
#添加 Jenkins 软件存储库
[root@localhost ~]# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
[root@localhost ~]# ll /etc/yum.repos.d/
总用量 64
-rw-r--r--. 1 root root 200 11月 28 15:02 AnolisOS-AppStream.repo
-rw-r--r--. 1 root root 191 11月 28 15:02 AnolisOS-BaseOS.repo
-rw-r--r--. 1 root root 341 1月 5 14:34 AnolisOS-DDE.repo
-rw-r--r--. 1 root root 182 11月 28 15:02 AnolisOS-DDE.repo.rpmnew
-rw-r--r--. 1 root root 1161 11月 28 15:02 AnolisOS-Debuginfo.repo
-rw-r--r--. 1 root root 191 11月 28 15:02 AnolisOS-Extras.repo
-rw-r--r--. 1 root root 221 11月 28 15:02 AnolisOS-HighAvailability.repo
-rw-r--r--. 1 root root 185 11月 28 15:02 AnolisOS-Plus.repo
-rw-r--r--. 1 root root 203 11月 28 15:02 AnolisOS-PowerTools.repo
-rw-r--r--. 1 root root 1091 11月 28 15:02 AnolisOS-Source.repo
-rw-r--r--. 1 root root 1698 10月 4 07:26 epel-modular.repo
-rw-r--r--. 1 root root 1332 10月 4 07:26 epel.repo
-rw-r--r--. 1 root root 1797 10月 4 07:26 epel-testing-modular.repo
-rw-r--r--. 1 root root 1431 10月 4 07:26 epel-testing.repo
-rw-r--r-- 1 root root 85 11月 30 2016 jenkins.repo
#导入 GPG 密钥以确保你的软件是合法的
[root@localhost ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
#注意:你可能已经注意到存储库列出了 Red Hat,但你的系统是 Anolis OS。因为Anolis OS 是从CentOS 继承过来的。
#查看可安装版本:
[root@localhost ~]# yum list --showduplicates jenkins
可安装的软件包
jenkins.noarch 1.409.1-1.1 jenkins
jenkins.noarch 1.409.2-1.1 jenkins
jenkins.noarch 1.409.3-1.1 jenkins
jenkins.noarch 1.424.1-1.1 jenkins
jenkins.noarch 1.424.2-1.1 jenkins
jenkins.noarch 1.424.3-1.1 jenkins
jenkins.noarch 1.424.4-1.1 jenkins
jenkins.noarch 1.424.5-1.1 jenkins
jenkins.noarch 1.424.6-1.1 jenkins
jenkins.noarch 1.447.1-1.1 jenkins
jenkins.noarch 1.447.2-1.1 jenkins
jenkins.noarch 1.466.1-1.1 jenkins
jenkins.noarch 1.466.2-1.1 jenkins
jenkins.noarch 1.480.1-1.1 jenkins
jenkins.noarch 1.480.2-1.1 jenkins
jenkins.noarch 1.480.3-1.1 jenkins
jenkins.noarch 1.509.1-1.1 jenkins
jenkins.noarch 1.509.2-1.1 jenkins
jenkins.noarch 1.509.3-1.1 jenkins
jenkins.noarch 1.509.4-1.1 jenkins
jenkins.noarch 1.532.1-1.1 jenkins
jenkins.noarch 1.532.2-1.1 jenkins
jenkins.noarch 1.532.3-1.1 jenkins
jenkins.noarch 1.554.1-1.1 jenkins
jenkins.noarch 1.554.2-1.1 jenkins
jenkins.noarch 1.554.3-1.1 jenkins
jenkins.noarch 1.565.1-1.1 jenkins
jenkins.noarch 1.565.2-1.1 jenkins
jenkins.noarch 1.565.3-1.1 jenkins
jenkins.noarch 1.580.1-1.1 jenkins
jenkins.noarch 1.580.2-1.1 jenkins
jenkins.noarch 1.580.3-1.1 jenkins
jenkins.noarch 1.596.1-1.1 jenkins
jenkins.noarch 1.596.2-1.1 jenkins
jenkins.noarch 1.596.3-1.1 jenkins
jenkins.noarch 1.609.1-1.1 jenkins
jenkins.noarch 1.609.2-1.1 jenkins
jenkins.noarch 1.609.3-1.1 jenkins
jenkins.noarch 1.625.1-1.1 jenkins
jenkins.noarch 1.625.2-1.1 jenkins
jenkins.noarch 1.625.3-1.1 jenkins
jenkins.noarch 1.642.1-1.1 jenkins
jenkins.noarch 1.642.2-1.1 jenkins
jenkins.noarch 1.642.3-1.1 jenkins
jenkins.noarch 1.642.4-1.1 jenkins
jenkins.noarch 1.651.1-1.1 jenkins
jenkins.noarch 1.651.2-1.1 jenkins
jenkins.noarch 1.651.3-1.1 jenkins
jenkins.noarch 2.7.1-1.1 jenkins
jenkins.noarch 2.7.2-1.1 jenkins
jenkins.noarch 2.7.3-1.1 jenkins
jenkins.noarch 2.7.4-1.1 jenkins
jenkins.noarch 2.19.1-1.1 jenkins
jenkins.noarch 2.19.2-1.1 jenkins
jenkins.noarch 2.19.3-1.1 jenkins
jenkins.noarch 2.19.4-1.1 jenkins
jenkins.noarch 2.32.1-1.1 jenkins
jenkins.noarch 2.32.2-1.1 jenkins
jenkins.noarch 2.32.3-1.1 jenkins
jenkins.noarch 2.46.1-1.1 jenkins
jenkins.noarch 2.46.2-1.1 jenkins
jenkins.noarch 2.46.3-1.1 jenkins
jenkins.noarch 2.60.1-1.1 jenkins
jenkins.noarch 2.60.2-1.1 jenkins
jenkins.noarch 2.60.3-1.1 jenkins
jenkins.noarch 2.73.1-1.1 jenkins
jenkins.noarch 2.73.2-1.1 jenkins
jenkins.noarch 2.73.3-1.1 jenkins
jenkins.noarch 2.89.1-1.1 jenkins
jenkins.noarch 2.89.2-1.1 jenkins
jenkins.noarch 2.89.3-1.1 jenkins
jenkins.noarch 2.89.4-1.1 jenkins
jenkins.noarch 2.107.1-1.1 jenkins
jenkins.noarch 2.107.2-1.1 jenkins
jenkins.noarch 2.107.3-1.1 jenkins
jenkins.noarch 2.121.1-1.1 jenkins
jenkins.noarch 2.121.2-1.1 jenkins
jenkins.noarch 2.121.3-1.1 jenkins
jenkins.noarch 2.138.1-1.1 jenkins
jenkins.noarch 2.138.2-1.1 jenkins
jenkins.noarch 2.138.3-1.1 jenkins
jenkins.noarch 2.138.4-1.1 jenkins
jenkins.noarch 2.150.1-1.1 jenkins
jenkins.noarch 2.150.2-1.1 jenkins
jenkins.noarch 2.150.3-1.1 jenkins
jenkins.noarch 2.164.1-1.1 jenkins
jenkins.noarch 2.164.2-1.1 jenkins
jenkins.noarch 2.164.3-1.1 jenkins
jenkins.noarch 2.176.1-1.1 jenkins
jenkins.noarch 2.176.2-1.1 jenkins
jenkins.noarch 2.176.3-1.1 jenkins
jenkins.noarch 2.176.4-1.1 jenkins
jenkins.noarch 2.190.1-1.1 jenkins
jenkins.noarch 2.190.2-1.1 jenkins
jenkins.noarch 2.190.3-1.1 jenkins
jenkins.noarch 2.204.1-1.1 jenkins
jenkins.noarch 2.204.2-1.1 jenkins
jenkins.noarch 2.204.3-1.1 jenkins
jenkins.noarch 2.204.4-1.1 jenkins
jenkins.noarch 2.204.5-1.1 jenkins
jenkins.noarch 2.204.6-1.1 jenkins
jenkins.noarch 2.222.1-1.1 jenkins
jenkins.noarch 2.222.3-1.1 jenkins
jenkins.noarch 2.222.4-1.1 jenkins
jenkins.noarch 2.235.1-1.1 jenkins
jenkins.noarch 2.235.2-1.1 jenkins
jenkins.noarch 2.235.3-1.1 jenkins
jenkins.noarch 2.235.4-1.1 jenkins
jenkins.noarch 2.235.5-1.1 jenkins
jenkins.noarch 2.249.1-1.1 jenkins
jenkins.noarch 2.249.2-1.1 jenkins
jenkins.noarch 2.249.3-1.1 jenkins
jenkins.noarch 2.263.1-1.1 jenkins
jenkins.noarch 2.263.2-1.1 jenkins
jenkins.noarch 2.263.3-1.1 jenkins
jenkins.noarch 2.263.4-1.1 jenkins
jenkins.noarch 2.277.1-1.1 jenkins
jenkins.noarch 2.277.2-1.1 jenkins
jenkins.noarch 2.277.3-1.1 jenkins
jenkins.noarch 2.277.4-1.1 jenkins
jenkins.noarch 2.289.1-1.1 jenkins
jenkins.noarch 2.289.2-1.1 jenkins
jenkins.noarch 2.289.3-1.1 jenkins
jenkins.noarch 2.303.1-1.1 jenkins
jenkins.noarch 2.303.2-1.1 jenkins
jenkins.noarch 2.303.3-1.1 jenkins
jenkins.noarch 2.319.1-1.1 jenkins
jenkins.noarch 2.319.2-1.1 jenkins
jenkins.noarch 2.319.3-1.1 jenkins
jenkins.noarch 2.332.1-1.1 jenkins
jenkins.noarch 2.332.2-1.1 jenkins
jenkins.noarch 2.332.3-1.1 jenkins
jenkins.noarch 2.332.4-1.1 jenkins
jenkins.noarch 2.346.1-1.1 jenkins
jenkins.noarch 2.346.2-1.1 jenkins
jenkins.noarch 2.346.3-1.1 jenkins
jenkins.noarch 2.361.1-1.1 jenkins
jenkins.noarch 2.361.2-1.1 jenkins
jenkins.noarch 2.361.3-1.1 jenkins
jenkins.noarch 2.361.4-1.1 jenkins
jenkins.noarch 2.375.1-1.1 jenkins
jenkins.noarch 2.375.2-1.1 jenkins
jenkins.noarch 2.375.3-1.1 jenkins
根据官网的https://mirrors.jenkins.io/war-stable/数据,TLS版本是稳定版,
支持jdk8的最高的是2.346.1版本,我们就安装这个版本。
#安装指定版本:
[root@localhost ~]# yum install jenkins-2.346.1-1.1
#更新到指定版本:
yum update jenkins-2.346.1-1.1
#使用yum安装程序时,提示xxx.rpm公钥尚未安装命令后加上--nogpgcheck跳过公钥检查
yum install jenkins-2.346.1-1.1 --nogpgcheck
3、第二种安装方式:直接下载 rpm 安装
官方似乎找不到rpm的包了,可以去清华大学开源软件镜像站下载:https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/
将下载好的rpm包上传到linux服务器,进入到刚才上传的rpm包所在的目录,执行安装命令:
[root@localhost ~]# rpm -ivh jenkins-2.346.1-1.1.noarch.rpm
4、修改Jenkins配置,按照上边的安装完成后直接启动的话会报错的,我们还需要修改一些配置
主要是修改两个地方:
第一个是账户:因为Jenkins默认的账户是jenkins的账户,这个账户没有创建,而且为了不因为权限出现各种问题,这里直接使用root,当然也可以创建一个名叫jenkins的账户;
第二个是端口:Jenkins的默认端口是8080,为了避免端口冲突,我们将它改掉
vim /etc/sysconfig/jenkins
第31行
JENKINS_USER="jenkins"
改为:
JENKINS_USER="root"
第58行
JENKINS_PORT="8080" #修改为你想要的端口
保存退出
这时候直接启动jenkins.service服务的话 还会报错
jenkins.service: Service RestartSec=100ms expired, scheduling restart.
Feb 12 15:54:47 localhost systemd[1]: jenkins.service: Scheduled restart job, restart counter is at 5.
Feb 12 15:54:47 localhost systemd[1]: Stopped Jenkins Continuous Integration Server.
Feb 12 15:54:47 localhost systemd[1]: jenkins.service: Start request repeated too quickly.
Feb 12 15:54:47 localhost systemd[1]: jenkins.service: Failed with result 'exit-code'.
Feb 12 15:54:47 localhost systemd[1]: Failed to start Jenkins Continuous Integration Server.
Feb 12 15:54:47 localhost systemd[1]:jenkins: failed to find a valid Java installation
这个时候需要修改/usr/lib/systemd/system/jenkins.service和/etc/init.d/jenkins
vim /etc/init.d/jenkins
第107行,将你的java的目录/usr/local/jdk1.8.0_11/bin/java填写上
99 candidates="
100 /etc/alternatives/java
101 /usr/lib/jvm/java-1.8.0/bin/java
102 /usr/lib/jvm/jre-1.8.0/bin/java
103 /usr/lib/jvm/java-11.0/bin/java
104 /usr/lib/jvm/jre-11.0/bin/java
105 /usr/lib/jvm/java-11-openjdk-amd64
106 /usr/bin/java
107 /usr/local/jdk1.8.0_11/bin/java
#保存后退出
vim /usr/lib/systemd/system/jenkins.service
第34行和35行,用户和用户组改为root
34 User=root
35 Group=root
保存后退出
重新加载服务文件
systemctl daemon-reload
最后,向/usr/bin/java 做一个软连接
[root@localhost ~]# which java
/usr/local/jdk1.8.0_11/bin/java
[root@localhost ~]# ln -s /usr/local/jdk1.8.0_11/bin/java /usr/bin/java
5、Jenkins使用
在浏览器输入:ip:8080,直接访问jenkens,例如:http://192.168.100.91:8080
image.png
输入管理员密码,点击继续。
[root@localhost ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
image.png
这里跳过插件安装,因为Jenkins插件需要连接默认官网下载,速度非常慢,而且经常会失败,所以暂时跳过插件安装。
image.png
创建用户,然后下一步。
image.png
6、安装插件
将jenkins的插件下载源更换为国内的
进入到jenkins的默认的开发目录
[root@localhost ~]# cd /var/lib/jenkins/
[root@localhost jenkins]# ll
总用量 40
-rw-r--r-- 1 root root 1660 2月 12 16:26 config.xml
-rw-r--r-- 1 root root 156 2月 12 16:26 hudson.model.UpdateCenter.xml
-rw------- 1 root root 1712 2月 12 16:06 identity.key.enc
-rw-r--r-- 1 root root 7 2月 13 09:49 jenkins.install.InstallUtil.lastExecVersion
-rw-r--r-- 1 root root 7 2月 13 09:49 jenkins.install.UpgradeWizard.state
-rw-r--r-- 1 root root 184 2月 13 09:49 jenkins.model.JenkinsLocationConfiguration.xml
-rw-r--r-- 1 root root 171 2月 12 16:06 jenkins.telemetry.Correlator.xml
drwxr-xr-x 2 root root 6 2月 12 16:06 jobs
drwxr-xr-x 3 root root 19 2月 13 05:22 logs
-rw-r--r-- 1 root root 907 2月 12 16:26 nodeMonitors.xml
drwxr-xr-x 2 root root 6 2月 12 16:06 nodes
drwxr-xr-x 2 root root 6 2月 12 16:06 plugins
-rw-r--r-- 1 root root 129 2月 12 16:11 queue.xml.bak
-rw-r--r-- 1 root root 64 2月 12 16:06 secret.key
-rw-r--r-- 1 root root 0 2月 12 16:06 secret.key.not-so-secret
drwx------ 2 root root 136 2月 13 09:49 secrets
drwxr-xr-x 2 root root 24 2月 12 16:06 userContent
drwxr-xr-x 3 root root 56 2月 13 09:49 users
6.1点击Manage Jenkins—>Manage Plugins—>Advanced
image.pngimage.png
在如图的位置将插件更新源替换为国内的清华大学更新地址:
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
然后点击submit按钮进行检查。
6.2点击Available,就会报如下的错误
image.pngThere were errors checking the update sites: SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
需要修改/var/lib/jenkins/updates/default.json 配置文件
将https://www.google.com/替换为https://www.baidu.com/
将https://updates.jenkins.io/download/替换成https://mirrors.tuna.tsinghua.edu.cn/jenkins/
保存后退出,然后重启jenkins服务。
安装插件Localization: Chinese时提示下载失败,详情如下:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:145)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:131)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
Caused: sun.security.validator.ValidatorException: PKIX path building failed
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1351)
Caused: javax.net.ssl.SSLHandshakeException
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1917)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:301)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:295)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1369)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:156)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:925)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:860)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1043)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1511)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at hudson.model.UpdateCenter$UpdateCenterConfiguration.testConnection(UpdateCenter.java:1406)
Caused: java.io.IOException: Failed to validate the SSL certificate of https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json?uctest
at hudson.model.UpdateCenter$UpdateCenterConfiguration.testConnection(UpdateCenter.java:1418)
at hudson.model.UpdateCenter$UpdateCenterConfiguration.checkUpdateCenter(UpdateCenter.java:1189)
at hudson.model.UpdateCenter$ConnectionCheckJob.run(UpdateCenter.java:1638)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.AtmostOneThreadExecutor$Worker.run(AtmostOneThreadExecutor.java:118)
at java.lang.Thread.run(Thread.java:745)
安装jenkins后下载插件报错日志,原因是因为默认证书有问题。
解决办法
URL地址更换为:
http://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
注意http连接没有s。
然后修改/var/lib/jenkins/updates/default.json 配置文件
将https://www.google.com/替换为http://www.baidu.com/
将https://updates.jenkins.io/download/替换成http://mirrors.tuna.tsinghua.edu.cn/jenkins/
保存后退出,然后重启jenkins服务。
注意,http://mirrors.tuna.tsinghua.edu.cn/jenkins/ 和http://www.baidu.com/ 都是http连接。
image.png汉化jenkins操作界面需要安装Localization: Chinese插件和Locale插件
image.png
安装好插件并重启jenkins服务后,还需要如下设置
Manage Jenkins--->Configure System--->Locale
在如下图的框中填写zh_CN,勾选下面的选项,依次点击Apply和save按钮,完成界面汉化。
image.png
重启服务后的登录页面:
image.png
登陆后的界面
image.png
参考文档:
https://blog.csdn.net/RookiexiaoMu_a/article/details/122655272
https://blog.csdn.net/jiangjun_dao519/article/details/125621587
https://www.jenkins.io/zh/download/
https://www.jenkins.io/zh/doc/book/installing/
https://blog.csdn.net/RookiexiaoMu_a/article/details/122655272
https://blog.csdn.net/qq_30273575/article/details/127491232
http://www.readke.com/c/557445.html