在 CentOS 上配置 Jenkins 一般分为几个步骤:
安装 Jenkins → 启动服务 → 开放端口 → 初始化配置 → 安装插件 & 创建任务。下面给你一个从零到可用的完整流程(适用于 CentOS 7 / 8 / Stream)。
Jenkins 需要 Java 8 或 Java 11/17
java -version
如果没有安装:
# CentOS 7
yum install -y java-11-openjdk java-11-openjdk-devel
# CentOS 8 / Stream
dnf install -y java-11-openjdk java-11-openjdk-devel
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
yum install -y jenkins
systemctl start jenkins
systemctl enable jenkins
systemctl status jenkins
Jenkins 默认端口是 8080
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
还需要在 安全组 / 防火墙 放行 8080
http://服务器IP:8080
cat /var/lib/jenkins/secrets/initialAdminPassword
复制密码 → 粘贴到页面 → 继续
选择: ✅ Install suggested plugins
常用插件包括:
初始化完成后:
编辑配置文件:
vim /etc/sysconfig/jenkins
修改:
JENKINS_PORT="8080"
重启:
systemctl restart jenkins
yum install -y git
Jenkins → Manage Jenkins → Global Tool Configuration → Git
echo "Hello Jenkins"
journalctl -u jenkins -xe
ss -lntp | grep 8080
firewall-cmd --list-ports
alternatives --config java
✅ 使用 Jenkins Pipeline
✅ 使用 Jenkinsfile
✅ 配置 权限管理(Role-based)
✅ 不要直接用 root 运行任务
✅ 定期备份 /var/lib/jenkins
如果你愿意,我可以帮你:
你现在用的是 CentOS 7 还是 8 / Stream?主要用来做什么项目?