在 Ubuntu 上部署或配置 GitLab 失败,原因可能有很多种。下面我从最常见原因 → 排查方法 → 典型场景解决给你系统梳理一下,你可以对照看是哪一种。
GitLab 官方要求:
表现:
gitlab-ctl reconfigure 卡死解决:
free -h
如果内存小:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
GitLab 默认占用:
常见冲突:
检查:
sudo netstat -tulnp | grep -E '80|443|8080'
解决:
sudo systemctl stop nginx
sudo systemctl disable nginx
或修改 GitLab 端口:
sudo vim /etc/gitlab/gitlab.rb
external_url 'http://your-ip:8081'
nginx['listen_port'] = 8081
错误示例:
external_url 'localhost'
正确示例:
external_url 'http://192.168.1.100'
# 或
external_url 'http://gitlab.example.com'
改完必须:
sudo gitlab-ctl reconfigure
典型错误:
/var/opt/gitlab 权限不对修复:
sudo gitlab-ctl stop
sudo chown -R root:root /var/opt/gitlab
sudo gitlab-ctl reconfigure
timedatectl
不同步会导致:
sudo apt install ntp
sudo timedatectl set-ntp true
sudo gitlab-ctl tail
或单独看:
sudo gitlab-ctl tail nginx
sudo gitlab-ctl tail puma
GitLab is taking too long to respond (502)✅ 内存不足 / Puma 没起来
✅ 检查:
sudo gitlab-ctl status
rails migration failed✅ PostgreSQL 没初始化成功
sudo gitlab-ctl reconfigure
sudo gitlab-rake db:migrate
Let's Encrypt verification failed✅ 80 端口被占用
✅ 域名未解析到服务器
external_url 'http://192.168.1.100'
puma['worker_processes'] = 2
postgresql['shared_buffers'] = "256MB"
请告诉我:
gitlab-ctl status 输出我可以直接帮你精准定位并给出修复命令。