GitLab幕后故事——异常处置篇

591 阅读3分钟

本文从 GitLab 管理者角度分享在 GitLab 实践中遇到的几个异常问题的应对方案

GitLab 后台问题

1、GitLab 重启失败

情景描述

  • GitLab 服务重启后查看状态
  • gitlab-ctl status
  • run:gitaly:(pid 17523)2436s;run:log:(pid 1659)65438385s 
    down:gitlab-workhorse:5084s,normally up;run:log:(pid 1672)65438385s 
    down:logrotate:5053s,normally up;run:log:(pid 1698)65438385s 
    down: nginx:4922s,normally up;run:log:(pid 1700)65438385s 
    down:postgresql:4891s,normally up;run:log:(pid 1675)65438385s 
    down:redis:4860s,normally up;run:log:(pid 1686)65438385s 
    down: sidekiq:3225s,normally up;run:log:( (pid1689)6 5438385s 
    run:unicorn:( (pid 7339)41s;run:log: (pid1670)65438385s
    

问题解决

  • 多次重启无果,查看 GitLab 日志文件发现 /tmp 目录不太对
  • 查看磁盘空间:df -h,根目录满了,GitLab 临时文件无法写入

image.png

  • 根目录扩容或者清出空间后,GitLab 重启成功

2、gitaly 服务重启失败

情景描述

  • gitaly 服务重启提示超时
  • gitlab-ctl restart gitaly
  • timeout: run: gitaly: (pid 1896) 694212s
    

问题解决

  • 强制关闭 gitaly 服务:
    • ps -ef | grep gitaly
    • kill -9 xxxx
  • 删除gitaly.pid:
    • find / -name gitaly.pid
    • rm -rf gitaly.pid
  • 重启gitaly 服务:
    • gitlab-ctl restart gitaly

3、GitLab 连接报错

情景描述

  • 在 Jenkins 打包、本地连接 GitLab 过程中出现类型报错:
    • stdout: 
      stderr:remote:HTTP Basic:Access denied 
      fatal:Authentication failed for'http://xxx.git/'
      

问题解决

  1. 核对用户名、密码是否正确
  2. 检查用户是否有操作权限(一般需要 Developer 及以上)

GitLab UI 问题

1、422 报错

GitLab 界面

image.png

问题解决

  • 422 报错从以下 2 方面入手解决:
    1. 检查本地时间和时区是否与服务端一致
    2. 更换浏览器重试,清除原浏览器缓存

2、502 报错

GitLab 界面

image.png

问题解决

  • 通过以下几个维度进行排查:
    1. 可能 GitLab 启动过程还未完成,通过 gitlab-ctl tail 查看进度,等待几分钟后刷新页面
    2. 检查系统内存占用情况,可能需要扩容
      • free -h
    3. 检查端口号是否被占用
      • netstat -anp |grep xxxx
    4. 重新加载配置,查看是否报错:
      • gitlab-ctl reconfigure
    5. 检查 GitLab 状态是否正常:
      • gitlab-rake gitlab:check SANITIZE=true --trace

3、500 报错

GitLab 界面

500.jpg

问题解决

  • 通过跟踪 production.log 日志查找报错,针对性修复:
    • 默认位置:/var/log/gitlab/gitlab-rails/production.log
    • 查找文件:find / -name production.log

4、无法登录

GitLab 界面

  • 页面没有用户名和密码输入框,显示:No authentication methods configured.

登录.jpg

问题解决

  1. 开启登录模块
  • 如果此时 GitLab 处于 root 账号登录状态中,从设置页面开启登录模块即可。

登录设置.jpg

  1. 数据库修改
  • 登录服务器,进入 GitLab 数据库:
    • gitlab-psql gitlabhq_production
  • # 修改登录项
    UPDATE application_settings set password_authentication_enabled=true;
    
    # 退出数据库
    \q
    
  • 重启 GitLab
    • gitlab-ctl restart