下面给你一个从零开始、可远程操作的 Debian + Jenkins 部署方案,适合你通过 SSH 远程服务器来完成。
ssh user@your_server_ip
Jenkins 需要 Java 11 或 17(推荐 17)
sudo apt update
sudo apt install -y openjdk-17-jdk
验证:
java -version
sudo apt install -y curl gnupg
sudo mkdir -p /usr/share/keyrings
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable 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
在你本地电脑执行:
ssh -L 8080:localhost:8080 user@your_server_ip
浏览器访问:
http://localhost:8080
sudo ufw allow 8080
访问:
http://your_server_ip:8080
⚠️ 公网直接暴露 Jenkins 风险极高,建议加 Nginx + HTTPS
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
sudo apt install -y nginx
配置示例(/etc/nginx/sites-enabled/jenkins):
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;
}
}
然后:
sudo nginx -t
sudo systemctl reload nginx
HTTPS 可用 Let’s Encrypt:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx
journalctl -u jenkins -xe
编辑:
sudo nano /etc/default/jenkins
修改:
JENKINS_PORT=9090
重启:
sudo systemctl restart jenkins
✅ 远程 Debian 部署 Jenkins 核心步骤:
如果你愿意,我可以:
你现在是 学习 / 公司项目 / 云服务器部署 哪种场景?