安装后首次启动卡在 “Please wait while Jenkins is getting ready…” 超过 10 分钟,如何定位是插件更新中心网络问题还是 systemd 限制?

解读

国内镜像源不稳定、公司代理或防火墙阻断 updates.jenkins.io 是高频场景;同时 CentOS 7/8 默认 90 秒 systemd 超时也会把“启动慢”伪装成“启动失败”。面试官想确认你能否快速区分“网络/插件”与“系统层限制”,并给出可落地的排查顺序,而不是盲目重启或换源。

知识点

  1. Jenkins 首次启动流程:
    • 生成初始管理员密码
    • 下载 update-center.json 校验插件索引
    • 并行下载依赖插件(hundreds MB)
  2. 国内网络卡点:
    • updates.jenkins.io 被 GFW 重置
    • 公司代理返回 407/502 导致无限重试
  3. systemd 默认 TimeoutStartSec=90s,Jenkins 未在 90 s 内向 systemd 通知 READY=1 即被杀进程,日志出现 Killed/Start-limit-hit
  4. 关键日志:
    • /var/log/jenkins/jenkins.log 中“Update site”下载耗时
    • systemctl status jenkins 中“Active: activating”或“failed (Result: timeout)”
  5. 工具:
    • curl -I https://updates.jenkins.io/update-center.json 验证网络
    • systemd-analyze blame 查看服务启动耗时
    • journalctl -u jenkins -b 捕捉被杀痕迹

答案

第一步确认 systemd 是否已超时杀死进程:
systemctl status jenkins 若看到“failed (Result: timeout)”或“Start-limit-hit”,则问题在 systemd;立即编辑 /usr/lib/systemd/system/jenkins.service 将 TimeoutStartSec=0(无超时)或 600 s,执行 systemctl daemon-reload && systemctl restart jenkins,观察 2 分钟内是否继续停留在启动页。

若状态仍为“activating”且进程存活,转向网络/插件问题:

  1. 在服务器上 tail -f /var/log/jenkins/jenkins.log,若出现“IOException”或“PKIX path building failed”即证书/代理问题;
  2. curl -o /dev/null -w '%{time_total}' https://updates.jenkins.io/update-center.json 耗时 >10 s 即网络瓶颈;
  3. 国内加速方案:
    • 在 Jenkins > Plugin Manager > Advanced 把 Update Site URL 改为 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json;
    • 或在启动前注入环境变量 JENKINS_UC=https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates;
  4. 若公司强制代理,给 Jenkins 用户写入 ~/.curlrc 或在 /etc/systemd/system/jenkins.service.d/proxy.conf 中设置 **Environment="HTTPS_PROXY=http://user:pass@proxy:8080"**,重载后重启。

验证:

  • systemd 不再超时,日志出现“Jenkins is fully up and running”且插件列表正常渲染,即定位完成。

拓展思考

  1. 提前离线化:
    生产环境可预下载官方“jenkins.war + 插件目录”,首次启动时挂载到 JENKINS_HOME/plugins,彻底避开外网依赖,满足金融、政务内网合规。
  2. 监控启动时长:
    在 Ansible/Terraform 模板里加入 systemd-analyze blame | grep jenkins 断言,若 >120 s 自动回滚镜像并报警,防止凌晨发布卡死。
  3. 升级后回归:
    Jenkins 2.4xx 版本后引入“plugin installation manager”工具,可在 CI 阶段用 jenkins-plugin-cli --latest false --war jenkins.war 预装插件,升级时只需替换 war 包,启动时间从 10 min 降到 30 s 内。