在 CentOS 上部署和配置 Jenkins,一般步骤如下(以 CentOS 7/8 为例,适用于 Jenkins LTS):
# CentOS 7/8
sudo yum install -y java-11-openjdk-devel
# 或
sudo dnf install -y java-11-openjdk-devel
验证:
java -version
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
sudo yum install -y jenkins
# 或
sudo dnf install -y jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo systemctl status jenkins
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
http://服务器IP:8080
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
复制密码粘贴到页面中。
选择 Install suggested plugins
编辑配置文件:
sudo vi /etc/sysconfig/jenkins
修改:
JENKINS_PORT="8080"
重启:
sudo systemctl restart jenkins
默认以 jenkins 用户运行,如需执行 Docker、Git 等:
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
server {
listen 80;
server_name jenkins.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
sudo journalctl -u jenkins
可更换为国内镜像:
系统管理 → 插件管理 → 高级 → 升级站点
使用:
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
如果你需要的是:
可以告诉我你的使用场景,我给你更具体的配置示例。