11

CentOS通过yum快速安装Jenkins

 9 months ago
source link: https://wiki.eryajf.net/pages/0b780e/#%E5%AE%89%E8%A3%85-jenkins
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

CentOS通过yum快速安装Jenkins

文章发布较早,内容可能过时,阅读注意甄别。

之前我比较迷信于使用 Tomcat 部署 Jenkins,而现在随时拉起的环境越发的多,反而感觉到这种方式比较麻烦,使用 yum 安装基于 systemd 管理似乎也是一个不错的选择。

这里使用当前最新的版本2.426.1来做演示,记录一下部署的过程。

# 安装 jdk

从 Jenkins 2.357(2022 年 6 月 28 日发布)和即将发布的 2.361.1 LTS 版本开始,Jenkins 需要 Java 11 或更高版本。所以这里我们要安装 jdk 11。

这里我选择 openjdk,并通过华为的国内镜像 (opens new window)进行下载,速度非常快。推荐给你。

$ wget https://mirrors.huaweicloud.com/openjdk/11.0.2/openjdk-11.0.2_linux-x64_bin.tar.gz

$ tar xf openjdk-11.0.2_linux-x64_bin.tar.gz

$ mv jdk-11.0.2/ /usr/local/jdk11
1
2
3
4
5

配置环境变量:

# 将如下内容写入 /etc/profile
$ export PATH=/usr/local/jdk11/bin:$PATH

验证效果:

$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
1701705708887.jpg

# 安装 Jenkins

要下载 Jenkins 的安装包,我推荐你通过我的 Thanks-Mirror (opens new window) 项目找到国内镜像站进行下载。这里通过清华的国内镜像下载。

$ wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.426.1-1.1.noarch.rpm
# 如果不安装 fontconfig 可能会遇到相关报错
$ yum -y install fontconfig
$ yum -y localinstall jenkins-2.426.1-1.1.noarch.rpm

调整启动配置文件:

$ egrep -v '^#|^$' /usr/lib/systemd/system/jenkins.service

[Unit]
Description=Jenkins Continuous Integration Server
Requires=network.target
After=network.target
[Service]
Type=notify
NotifyAccess=main
ExecStart=/usr/bin/jenkins
Restart=on-failure
SuccessExitStatus=143
User=jenkins
Group=jenkins
Environment="JENKINS_HOME=/data/.jenkins"
WorkingDirectory=/data/.jenkins
Environment="JENKINS_WEBROOT=%C/jenkins/war"
Environment="JAVA_HOME=/usr/local/jdk11"
Environment="JAVA_OPTS=-Djava.awt.headless=true"
Environment="JENKINS_PORT=8080"
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

通常你可能需要调整工作目录,另外注意指定 JAVA_HOME 为自己安装的 jdk 位置,其他参数根据情况调整。

如果你像我一样,也更改了家目录,那么需要单独创建并调整权限:

$ mkdir /data/.jenkins
$ chown -R jenkins.jenkins /data/.jenkins

启动服务:

$ systemctl daemon-reload
$ systemctl start jenkins

如果没有报错,那么 Jenkins 将会正常启动,然后,即可享用之。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK