GitLab 升级后 502:Puma 反复重启问题处理记录

一、问题现象

GitLab 升级后,页面访问返回:

复制代码
502 Bad Gateway

查看服务状态:

复制代码
gitlab-ctl status

大部分服务都是 run,但发现 puma 运行时间很短:

复制代码
run: puma: (pid xxx) 9s

说明 puma 服务在反复重启,并没有真正稳定运行。


二、排查过程

查看 gitlab-workhorse 日志:

复制代码
tail -n 100 /var/log/gitlab/gitlab-workhorse/current

发现报错:

复制代码
dial unix /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket:
connect: no such file or directory

说明 gitlab-workhorse 找不到 gitlab.socket。

GitLab Web 请求链路大致是:

复制代码
nginx -> gitlab-workhorse -> puma -> GitLab Rails

gitlab.socket 是 Puma 启动成功后生成的。

现在 socket 不存在,说明 Puma 没有正常启动。

继续查看 Puma 日志:

复制代码
tail -n 100 /var/log/gitlab/puma/current

发现核心报错:

复制代码
TZInfo::DataSources::InvalidZoneinfoFile
The file '/usr/share/zoneinfo/zone_utc' does not start with the expected header.

由此判断:Puma 启动时加载系统时区文件失败,导致服务反复重启。


三、确认原因

检查时区文件:

复制代码
file /usr/share/zoneinfo/zone_utc
file /usr/share/zoneinfo/UTC
file /usr/share/zoneinfo/Etc/UTC

返回类似:

复制代码
/usr/share/zoneinfo/zone_utc: UTF-8 Unicode text
/usr/share/zoneinfo/UTC: timezone data
/usr/share/zoneinfo/Etc/UTC: timezone data

正常时区文件应该是 timezone data,但 /usr/share/zoneinfo/zone_utc 是普通文本文件。

所以根因是:

复制代码
/usr/share/zoneinfo/zone_utc 文件异常,导致 Ruby tzinfo 加载失败,Puma 启动失败,最终 GitLab 返回 502。

四、解决方法

先停止 Puma:

复制代码
gitlab-ctl stop puma

将异常文件移出 /usr/share/zoneinfo:

复制代码
mkdir -p /root/zoneinfo_bad_backup

mv /usr/share/zoneinfo/zone_utc /root/zoneinfo_bad_backup/zone_utc.bad.$(date +%F_%H%M%S)

验证 tzinfo 是否正常:

复制代码
/opt/gitlab/embedded/bin/ruby -e 'require "tzinfo"; TZInfo.eager_load!; puts "tzinfo ok"'

正常输出:

复制代码
tzinfo ok

启动 Puma:

复制代码
gitlab-ctl start puma

等待一会儿后检查状态:

复制代码
sleep 60
gitlab-ctl status

如果看到 Puma 运行时间持续增长,说明已经恢复:

复制代码
run: puma: (pid xxx) 60s

然后重启 Web 相关组件:

复制代码
gitlab-ctl restart gitlab-workhorse
gitlab-ctl restart nginx

测试访问:

复制代码
curl -I http://127.0.0.1

或 HTTPS:

复制代码
curl -k -I https://127.0.0.1

正常返回 200 或 302,GitLab 页面即可恢复访问。


五、问题总结

本次 GitLab 升级后 502 的根因不是 nginx,也不是 workhorse,而是 Puma 启动失败。

完整链路如下:

复制代码
zone_utc 时区文件异常
        ↓
Ruby tzinfo 加载失败
        ↓
Puma 启动失败并反复重启
        ↓
gitlab.socket 没有生成
        ↓
gitlab-workhorse 无法连接 Rails 后端
        ↓
GitLab 页面返回 502

六、经验总结

GitLab 升级后如果出现 502,不要只看 gitlab-ctl status 是否都是 run,还要重点关注服务运行时间。

如果 puma 一直只有几秒或几十秒,说明它可能在反复重启。

建议优先排查:

复制代码
gitlab-ctl status
tail -n 100 /var/log/gitlab/puma/current
tail -n 100 /var/log/gitlab/gitlab-workhorse/current
ls -lh /var/opt/gitlab/gitlab-rails/sockets/

其中,gitlab.socket 是否存在,是判断 Puma 是否真正启动成功的重要依据。

相关推荐
分布式存储与RustFS3 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
玉&心3 天前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing3 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
guo_wen_qiang3 天前
上传本地镜像到harbor中
docker·容器·持续部署
羑悻的小杀马特3 天前
Dockerfile 全景指南:从入门编写dockerfile到生产环境镜像优化实战,一步步带你从啃透制作指令到镜像制作落地!
docker·dockerfile·镜像制作
BianHuanShiZhe3 天前
docker常见命令
docker
正经教主3 天前
【FDE系列】阶段2:Day 43:Docker Compose — 多容器一键编排
人工智能·docker·fde
忆~遂愿3 天前
本地片库怎么在外面打开?Plex + cpolar 搭一套可远程访问的私人影音库
docker·容器
Zhu7583 天前
docker环境,vLLM 部署 Qwen3.8-27B
docker·qwen·vllm
溜达的大象3 天前
多台服务器不想上重型监控?用 Beszel 搭一套轻量主机与 Docker 看板
docker