下面给你一份在 Debian 上从零跑起 Jenkins的实用步骤(以 Debian 11/12 为例,适用于大多数情况)。
sudo apt update
sudo apt upgrade -y
Jenkins 需要 Java 11 或 Java 17(推荐 17)
sudo apt install -y openjdk-17-jdk
验证:
java -version
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian binary/" \
| sudo tee /etc/apt/sources.list.d/jenkins.list
sudo apt update
sudo apt install -y jenkins
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
看到 active (running) 就成功了。
sudo ufw allow 8080
http://<服务器IP>:8080
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
复制到浏览器页面中。
按提示设置用户名、密码、邮箱。
修改端口:
sudo nano /etc/default/jenkins
改:
JENKINS_PORT=9090
重启:
sudo systemctl restart jenkins
通常是:
sudo nano /var/lib/jenkins/hudson.model.UpdateCenter.xml
改为:
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
sudo apt install nginx
Nginx 示例:
server {
listen 80;
server_name jenkins.example.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
如果你愿意,可以告诉我:
我可以直接给你最适合你环境的方案。