文章目录
1. Java版本兼容列表
Jenkins | Java |
---|---|
Jenkins 2.164 及 以上 | Java 8 or Java 11 |
Jenkins 2.54 ~ Jenkins 2.164(不包括) | Java 8 |
Jenkins 1.612 ~ Jenkins 2.54(不包括) | Java 7 |
2. JDK安装
请参考《CentOS安装JDK与配置环境变量》进行安装;
3. Jenkins安装
前提:CentOS/Redhat安装Jenkins在Jenkins官方文档中已写得很清楚了,本文只做简单安装案例以及处理遇到的问题的阐述;
3.1 定义Jenkins RPM仓库
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
若出现如下错误:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
--2022-02-25 16:02:30-- https://pkg.jenkins.io/redhat-stable/jenkins.repo
正在解析主机 pkg.jenkins.io (pkg.jenkins.io)... 151.101.74.133, 2a04:4e42:11::645
正在连接 pkg.jenkins.io (pkg.jenkins.io)|151.101.74.133|:443... 已连接。
错误: 无法验证 pkg.jenkins.io 的由 “/C=US/O=Let's Encrypt/CN=R3” 颁发的证书:
颁发的证书已经过期。
要以不安全的方式连接至 pkg.jenkins.io,使用“--no-check-certificate”。
则根据提示在命令中添加--no-check-certificate
参数,如下:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo --no-check-certificate
成功后,再执行key导入命令,如下:
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
3.2 进行安装
# 安装epel-release
yum install epel-release -y
# 安装jenkins
yum install jenkins -y
4. Jenkins启动
4.1 指定Java程序
修改/etc/init.d/jenkins系统服务启动脚本,在其70几行找到candidates变量,在该变量中添加上需要指定的java程序(以绝对路径方式:$JAVA_HOME/bin/java),如下:
vim /etc/init.d/jenkins
# ......
72 # Search usable Java as /usr/bin/java might not point to minimal version required by Jenkins.
73 # see http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
74 candidates="
75 /etc/alternatives/java
76 /usr/lib/jvm/java-1.8.0/bin/java
77 /usr/lib/jvm/jre-1.8.0/bin/java
78 /usr/lib/jvm/java-11.0/bin/java
79 /usr/lib/jvm/jre-11.0/bin/java
80 /usr/lib/jvm/java-11-openjdk-amd64
81 /usr/bin/java
# 指定的Java程序
82 /usr/local/java/openjdk/jdk8u312-b07/bin/java
83 "
84 for candidate in $candidates
85 do
86 [ -x "$JENKINS_JAVA_CMD" ] && break
87 JENKINS_JAVA_CMD="$candidate"
88 done
# ......
执行重载系统服务命令
systemctl daemon-reload
4.2 相关命令
# 启动
systemctl start jenkins
# 停止
systemctl stop jenkins
# 开机自启
systemctl enable jenkins
# 禁止自启
systemctl disable jenkins
# 查看状态
systemctl status jenkins
5. FAQ
5.1 目录介绍
程序目录:/usr/lib/jenkins
配置文件:/etc/sysconfig/jenkins
日志目录:/var/log/jenkins
缓存目录:/var/cache/jenkins
启动脚本:/etc/init.d/jenkins(/etc/rc.d/init.d/jenkins)
5.2 AWT is not properly configured on this server. Perhaps you need to run your container with “-Djava.awt.headless=true”?
原因:JDK版本原因
# CentOS7
yum install fontconfig -y
# CentOS6
yum install dejavu-sans-fonts
5.3 反向代理设置有误
针对Nginx配置,处理方式如下:
server {
listen 443 ssl;
server_name jenkins.domain.com;
access_log logs/server_jenkins.log main;
ssl_certificate /usr/local/nginx/ssl/fullchain.crt;
ssl_certificate_key /usr/local/nginx/ssl/private.pem;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location ^~ / {
proxy_pass http://jenkins;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 注意这项配置
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
}
}