下面按**“在 CentOS 上安装并配置 Jenkins”**的常见流程来说明,适用于 CentOS 7 / 8 / Stream,包含基础设置、权限、端口、开机启动等。
# CentOS 7/8
yum install -y java-11-openjdk-devel
# 或
dnf install -y java-11-openjdk-devel
java -version
Jenkins 2.3xx 推荐 Java 11 或 17
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install -y jenkins
# 或
dnf install -y jenkins
systemctl start jenkins
systemctl enable jenkins
systemctl status jenkins
Jenkins 默认端口:8080
# firewalld
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
# 或 iptables
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
浏览器访问:
http://服务器IP:8080
cat /var/lib/jenkins/secrets/initialAdminPassword
粘贴到页面中。
| 作用 | 路径 |
|---|---|
| 主目录 | /var/lib/jenkins |
| 配置文件 | /etc/sysconfig/jenkins |
| 日志 | /var/log/jenkins/jenkins.log |
编辑配置文件:
vi /etc/sysconfig/jenkins
常见修改:
JENKINS_PORT="8080"
JENKINS_USER="jenkins"
修改后重启:
systemctl restart jenkins
如果 Jenkins 要执行 Docker、部署等:
usermod -aG docker jenkins
chmod 777 /var/run/docker.sock
或直接使用 root 运行(不推荐生产)。
server {
listen 80;
server_name jenkins.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
systemctl status jenkinsjournalctl -u jenkinswhich java
确保是 Java 11+
如果你需要的是:
可以告诉我你的使用场景,我可以给你更具体的配置示例。