温馨提示×

GitLab Linux故障排查方法

小樊
33
2025-12-20 12:43:26
栏目: 智能运维

GitLab Linux故障排查方法

一 快速定位与通用检查

  • 查看整体状态与组件健康:执行gitlab-ctl status,定位异常组件(如unicorn/puma、gitaly、postgresql、redis、nginx)。
  • 集中查看日志:执行gitlab-ctl tail(或 tail -f /var/log/gitlab/gitlab-ctl/production.log)获取实时错误线索。
  • 资源与系统线索:用top/htop观察CPU/内存/IO,使用journalctl -xetail -f /var/log/syslogdmesg排查系统层报错。
  • 网络连通与解析:用pingnslookup/dig测试可达性与DNS;必要时检查**/etc/network/interfaces/etc/sysconfig/network-scripts/ifcfg-***等网络配置。
  • 防火墙放行:在CentOS执行firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload;在Debian/Ubuntu确认ufw/iptables策略。
  • 配置生效:修改**/etc/gitlab/gitlab.rb后务必执行gitlab-ctl reconfigure**,必要时gitlab-ctl restart

二 常见故障与处理清单

症状 快速检查 处理要点
访问页面显示502 Bad Gateway gitlab-ctl status;gitlab-ctl tail;检查端口占用 多为上游未就绪或端口冲突。确认unicorn/puma、gitaly、nginx均Running;用lsof -i:80/443查占用并释放;必要时重启相关服务与整体实例。
服务无法启动或配置错误 gitlab-ctl tail;核对/etc/gitlab/gitlab.rb 回滚最近变更,逐项注释可疑配置;执行gitlab-ctl reconfigure重建配置;查看组件日志定位根因。
安装依赖或执行reconfigure失败 安装日志、缺失依赖提示 CentOS/RHEL安装常见依赖:curl、policycoreutils(-python-utils)、openssh-server、postfix;在Debian/Ubuntu保持系统包为最新。
端口80/443被占用 lsof -i:80 / lsof -i:443 停止占用进程或调整**external_url ‘http://ip:port’**改用未占用端口;重启服务。
Permission denied 或目录不可写 ls -ld /var/log/gitlab /var/opt/gitlab 校正目录属主属组与权限,确保GitLab系统用户对日志与数据目录可写。
SELinux 拒绝访问 sestatus;/var/log/audit/audit.log 查看SELinux状态与拒绝记录;必要时执行semanage fcontext -a -t httpd_sys_rw_content_t “/var/log/gitlab(/.*)?” && restorecon -Rv /var/log/gitlab
内存不足导致卡顿/崩溃 free -m、top/htop 建议至少4GB内存;临时启用swap;优化并发与缓存策略,减少同时任务。
克隆/推送失败(SSH/HTTPS) ssh -T git@host;检查远程URL 校验SSH密钥HTTPS令牌;确认仓库URL(SSH/HTTPS)与端口正确;检查用户权限。
时间不一致引发异常 date;timedatectl status 校准服务器时间与时区,启用NTP同步,避免签名/作业调度异常。

三 系统差异要点

  • CentOS/RHEL
    • 依赖安装:yum install -y curl policycoreutils(-python-utils) openssh-server postfix
    • 防火墙放行:firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload
    • SELinux:异常时使用semanage/restorecon修复日志与数据目录上下文。
  • Debian/Ubuntu
    • 系统日志:tail -f /var/log/syslog;资源与启动项用systemctl管理。
    • 保持系统更新:apt update && apt upgrade;网络/DNS问题优先排查**/etc/network/interfaces**与DNS配置。
  • Docker 部署
    • 端口映射冲突或iptables异常时,先systemctl restart docker再启动容器;确保卷映射与权限正确。

四 数据保护与恢复

  • 备份:执行gitlab-rake gitlab:backup:create,默认备份目录为**/var/opt/gitlab/backups**。
  • 恢复:执行gitlab-rake gitlab:backup:restore BACKUP=xxx(xxx为备份文件名),恢复前确保实例已停止相关写入并妥善选择时间点。

五 高频命令速查

  • 状态与日志:gitlab-ctl statusgitlab-ctl tail;tail -f /var/log/gitlab/gitlab-rails/production.log
  • 配置与重启:编辑**/etc/gitlab/gitlab.rb后执行gitlab-ctl reconfiguregitlab-ctl restart**。
  • 端口与连通:lsof -i:80 / lsof -i:443pingnslookup/dig;检查防火墙规则。
  • 系统资源与内核:top/htopfree -m;按需调整vm.swappinesstimedatectl校准时间。

0