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

正常返回 200302,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 是否真正启动成功的重要依据。

相关推荐
梦之美丽生活6 小时前
【本地部署及docker部署】yolov8_detect
yolo·docker·容器
毕竟是shy哥7 小时前
windows电脑WSL下本地构建docker镜像
windows·docker·容器
上学的小垃圾15 小时前
基于docker安装MySQL(openEuler系统)
linux·mysql·docker·容器
Raas1001 天前
MAI Gateway(魔芋企业级AI网关)详解:AI网关在架构中的位置,一文读懂企业AI流量治理
大数据·人工智能·架构·gateway·ai网关·mai gateway
小小程序员.¥1 天前
docker中redis集群配置
docker
Raas1001 天前
AI网关在架构中的位置?MAI Gateway(魔芋企业级AI网关)给出企业级答案
大数据·网络·人工智能·架构·gateway·ai网关·mai gateway
java_logo1 天前
Docker 部署 HertzBeat:轻松搭建无代理实时监控与告警平台
运维·docker·容器·监控告警·部署教程·hertzbeat·轩辕镜像
子建莫敌1 天前
Docker 速查手册
docker·容器
雾隐隐o1 天前
Docker 镜像归档与容器管理
java·docker·eureka