GitLab Linux服务器故障排查指南
使用gitlab-ctl status命令查看GitLab各组件(如gitlab-rails、nginx、postgresql等)的运行状态。若组件显示为“down”或“unhealthy”,可通过gitlab-ctl restart <组件名>重启特定组件,或gitlab-ctl restart重启所有服务。
日志是故障排查的核心依据,GitLab的日志主要分布在/var/log/gitlab目录下:
/var/log/gitlab/gitlab-rails/production.log(记录Web请求、数据库操作等);/var/log/gitlab/nginx/gitlab_access.log(访问日志)、/var/log/gitlab/nginx/gitlab_error.log(错误日志);/var/log/gitlab/gitlab-shell/gitlab-shell.log(Shell操作)、/var/log/gitlab/unicorn/unicorn_stdout.log(Unicorn进程)。 可使用tail -f <日志文件>实时查看日志流,或grep "error" <日志文件>过滤错误信息。GitLab的主配置文件为/etc/gitlab/gitlab.rb,修改后需执行gitlab-ctl reconfigure重新加载配置(不会重启服务),gitlab-ctl restart重启所有服务使配置生效。重点检查以下配置项:
external_url:确保URL格式正确(如http://your-server-ip或带端口的http://your-server-ip:8080);nginx['ssl_certificate']和nginx['ssl_certificate_key']是否指向有效证书;postgresql['host']、postgresql['port']等参数是否正确。使用以下命令监控服务器资源使用情况,资源不足(如CPU、内存耗尽或磁盘空间满)可能导致GitLab服务异常:
top(动态查看)、htop(更直观)、free -m(内存使用量,单位MB);df -h(查看各分区使用率,重点关注/var/opt/gitlab目录,GitLab数据默认存储于此);iotop(查看磁盘读写负载,需安装yum install iotop -y)。ping <IP/域名>检查服务器是否能访问外网(如ping 8.8.8.8),或ping gitlab.example.com测试域名解析;netstat -tulnp | grep <端口>或ss -tulnp | grep <端口>查看GitLab所需端口(如80、443、22)是否监听;firewall-cmd --list-all(CentOS)或ufw status(Ubuntu)查看防火墙规则,确保GitLab端口开放(如firewall-cmd --add-service=http --permanent、firewall-cmd --reload)。/etc/gitlab/nginx/conf.d/gitlab-http.conf)、GitLab应用是否运行(gitlab-ctl status);/var/log/gitlab/gitlab-rails/production.log或项目→CI/CD→Jobs→Job Logs),常见问题包括依赖未安装(如apt-get install -y nodejs)、环境变量未配置(如CI_SECRET缺失);gitlab-runner status检查Runner状态,gitlab-runner restart重启Runner,或重新注册Runner(gitlab-runner register)。atop(监控CPU、内存、IO,yum install atop -y)、vmstat(查看系统整体性能,vmstat 1 5每秒刷新一次,共5次);gitlab-rake gitlab:backup:create命令创建备份(默认存储在/var/opt/gitlab/backups目录),建议开启自动备份(修改/etc/gitlab/gitlab.rb中的gitlab_rails['backup_keep_time'] = 604800,保留7天);gitlab-ctl stop unicorn、gitlab-ctl stop sidekiq),执行gitlab-rake gitlab:backup:restore BACKUP=<备份文件名>(如BACKUP=1716451200_2024_05_20_13.15.0),恢复后重启服务(gitlab-ctl start)。