1. 查看安装
1.1 显示 Linux 系统的详细信息,包括内核版本、操作系统版本和其他相关信息
uname -a
1.2 查看 Red Hat Linux 系统的版本
cat /etc/redhat-release
# 或者
cat /etc/os-release
1.3 查看 JDK 是否安装
java -version
#查看安装路径
echo $JAVA_HOME
1.4 查看 8080 端口是否被占用
# 查询占用端口
netstat -tln | grep 8080
# 查询占用端口的进程 ID
lsof -i :2810
8080已被使用,需要修改Jenkins默认端口,请继续往下看
2. Jenkins 传送门
- Jenkins 官网
- Red Hat/Alma/Rocky 安装路径
3. 安装步骤
3.1 Jenkins 源安装
# 获取 Jenkins 源
# 官方源安装
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
# 下载 GPG 密钥
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
网络受限可使用:清华大学开源软件镜像站
3.2 执行安装
yum install jenkins
# 重新加载 systemd 的配置文件
sudo systemctl daemon-reload
3.3 启用 Jenkins 自启动
sudo systemctl enable jenkins
执行后出现
Created symlink `/etc/systemd/system/multi-user.target.wants/jenkins.service` → /usr/lib/systemd/system/jenkins.service.
找到/etc/systemd/system/multi-user.target.wants/jenkins.service
文件可修正端口和 JDK 路径
3.4 修改端口和 JDK 路径
cd /etc/systemd/system/multi-user.target.wants/
vi jenkins.service
JDK 路径
修改前:
# Environment="JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64"
修改后:
Environment="JAVA_HOME=/usr/java/java-11-openjdk-11.0.17-2"
端口
修改前:
Environment="JENKINS_PORT=8080"
修改后:
Environment="JENKINS_PORT=8181"
3.5 再次启用 Jenkins 自启动
sudo systemctl enable jenkins
3.6 启动 Jenkins 服务
sudo systemctl start jenkins
# 执行完成后
# Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.
3.7 检查 Jenkins 服务状态
sudo systemctl status jenkins
执行完成后
#执行完成后
● jenkins.service - Jenkins Continuous Integration ServerLoaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; vendor preset: disabled)Active: active (running) since Fri 2024-04-05 02:03:08 JST; 1min 9s agoMain PID: 688800 (java)Tasks: 44 (limit: 48554)Memory: 2.1GCGroup: /system.slice/jenkins.service└─688800 /usr/java/java-11-openjdk-11.0.17-2/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=81814月 05 02:02:46 svn.taulus.com jenkins[688800]: Jenkins initial setup is required. An admin user has been created and a password generated.4月 05 02:02:46 svn.taulus.com jenkins[688800]: Please use the following password to proceed to installation:4月 05 02:02:46 svn.taulus.com jenkins[688800]: 0e84bf0fe4354cb18c6df13b9d47b2944月 05 02:02:46 svn.taulus.com jenkins[688800]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword4月 05 02:02:46 svn.taulus.com jenkins[688800]: *************************************************************4月 05 02:03:08 svn.taulus.com jenkins[688800]: 2024-04-04 17:03:08.136+0000 [id=30] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization4月 05 02:03:08 svn.taulus.com jenkins[688800]: 2024-04-04 17:03:08.236+0000 [id=22] INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and runni>4月 05 02:03:08 svn.taulus.com systemd[1]: Started Jenkins Continuous Integration Server.4月 05 02:03:08 svn.taulus.com jenkins[688800]: 2024-04-04 17:03:08.966+0000 [id=47] INFO h.m.DownloadService$Downloadable#load: Obtained the updated data >4月 05 02:03:08 svn.taulus.com jenkins[688800]: 2024-04-04 17:03:08.967+0000 [id=47] INFO hudson.util.Retrier#start: Performed the action check updates ser>
lines 1-19/19 (END)
Connection closed by foreign host.Disconnected from remote host(192.168.166.199) at 17:17:59.
生成登录密码:0e84bf0fe4354cb18c6df13b9d47b294
4. 登录 Jenkins
输入 localhost:8181
,并输入密码即可