温馨提示×

怎样调试linux gitlab

小樊
45
2026-10-13 08:00:52
栏目: 智能运维

调试 Linux 上的 GitLab 通常分为服务状态排查、日志分析、配置验证、常见故障处理几个层面。下面给你一套比较系统的做法,从“先看病”到“动手修”。


一、先确认 GitLab 服务状态

1. 查看整体服务状态(Omnibus 安装)

sudo gitlab-ctl status

正常应看到:

  • runsvdir
  • nginx
  • puma / unicorn
  • sidekiq
  • postgresql
  • redis
  • gitaly

如果有 down,说明对应组件异常。

2. 启动 / 重启服务

sudo gitlab-ctl start
sudo gitlab-ctl restart
sudo gitlab-ctl stop

二、查看日志(最重要)

1. 查看全部日志

sudo gitlab-ctl tail

2. 按需查看具体组件日志

sudo gitlab-ctl tail nginx
sudo gitlab-ctl tail puma
sudo gitlab-ctl tail sidekiq
sudo gitlab-ctl tail postgresql
sudo gitlab-ctl tail gitaly

3. 常见关键日志位置

/var/log/gitlab/
  • nginx/gitlab_error.log
  • puma/puma_stderr.log
  • sidekiq/current
  • postgresql/postgresql.log

三、检查配置文件

1. 主配置文件

sudo vim /etc/gitlab/gitlab.rb

常见检查项:

  • external_url
  • nginx['listen_port']
  • gitlab_rails['gitlab_email_from']
  • postgresql['enable']

2. 修改配置后必须重配

sudo gitlab-ctl reconfigure

四、常用调试命令

1. 检查配置是否合法

sudo gitlab-rake gitlab:check

2. 检查 GitLab 环境

sudo gitlab-rake gitlab:env:info

3. 测试邮件发送

sudo gitlab-rails console
Notify.test_email('you@example.com', 'Test', 'Hello').deliver_now

五、常见故障与排查思路

1. 页面打不开(502)

可能原因:

  • puma / unicorn 没启动
  • 端口冲突
  • 内存不足(OOM)

排查:

sudo gitlab-ctl status
free -h
sudo gitlab-ctl tail puma

2. Git 拉取 / 推送失败

  • SSH 问题:
ssh -T git@your-gitlab.com
  • HTTP 问题:
curl -v http://gitlab

3. 数据库问题

sudo gitlab-psql

或查看:

sudo gitlab-ctl tail postgresql

4. 磁盘满

df -h
du -sh /var/opt/gitlab/*

常见爆盘目录:

  • backups
  • artifacts
  • registry

六、进入 Rails 控制台调试(高级)

sudo gitlab-rails console

可以:

  • 查用户
  • 重置密码
  • 看异常对象

示例:

User.find_by(username: 'root').password='12345678'
User.find_by(username: 'root').save!

七、如果你用的是 Docker GitLab

docker logs gitlab
docker exec -it gitlab gitlab-ctl status

如果你愿意,可以告诉我:

  • ✅ GitLab 安装方式(Omnibus / Docker / 源码)
  • ✅ 具体报错信息或现象(502?SSH 失败?CI 不跑?)
  • ✅ Linux 发行版和版本

我可以直接帮你定位具体问题并给出修复命令。

0 踩