GitLab在Linux上的故障排查指南
gitlab-ctl status命令检查GitLab各组件(如nginx、postgresql、unicorn等)的运行状态。若组件显示为“down”或“unhealthy”,需进一步排查对应服务的日志或尝试重启服务(gitlab-ctl restart <component_name>)。top、htop、free -m(内存)、df -h(磁盘空间)等命令监控系统资源使用情况。若内存占用超过80%、磁盘空间剩余不足10%,可能导致GitLab响应缓慢或服务崩溃,需清理无用文件(如过期构建产物、日志)或扩容服务器。/var/log/gitlab目录,其中:
/var/log/gitlab/gitlab-rails/production.log(记录请求处理、数据库操作等);/var/log/gitlab/gitlab-rails/production_json.log(JSON格式的异常详情);/var/log/gitlab/nginx/gitlab_error.log(网络/代理错误);/var/log/gitlab/gitlab-shell.log(SSH操作)、/var/log/gitlab/unicorn/*.log(Unicorn服务器日志)。gitlab-ctl tail命令实时输出所有组件的日志,或通过tail -f /var/log/gitlab/gitlab-rails/production.log跟踪特定日志文件,快速定位错误发生时间点及相关上下文。/etc/gitlab/gitlab.rb,需重点核查以下关键配置:
external_url:确保URL格式正确(如http://yourdomain.com或https://yourdomain.com),且与实际访问地址一致;nginx['ssl_certificate']和nginx['ssl_certificate_key']路径是否指向有效证书,证书是否过期;postgresql['host']、postgresql['port']等参数是否正确(默认本地数据库为localhost:5432)。gitlab-ctl reconfigure命令重新应用配置(该命令会自动检查配置语法并更新服务配置),然后重启GitLab服务(gitlab-ctl restart)使变更生效。curl、openssh-server)、配置文件错误。netstat -tulnp | grep <port>检查端口占用情况,终止冲突进程或修改GitLab端口;yum install -y curl policycoreutils-python openssh-server安装缺失依赖;gitlab-ctl reconfigure修复配置语法问题。/var/opt/gitlab/git-data/repositories),确保git用户拥有读写权限(chown -R git:git /var/opt/gitlab/git-data);~/.ssh/id_rsa.pub),或HTTPS Token是否有效。/var/log/gitlab/gitlab-rails/production.log,定位具体错误(如数据库超时需优化查询,代码异常需修复应用)。gitlab-ctl status确认unicorn服务运行状态,查看/var/log/gitlab/unicorn/*.log中的错误日志,重启unicorn(gitlab-ctl restart unicorn)。gitlab-runner list检查Runner状态,未注册则执行gitlab-runner register并填写正确的GitLab URL及Token;gcc、python、docker);API_KEY)。gitlab-rake gitlab:cleanup:orphan_pipeline_caches;docker image prune -a;