在 Debian 上安装 GitLab(通常指 GitLab CE / EE 官方 Omnibus 包)时,有几个非常关键的点容易踩坑。下面按「重要性 + 实操建议」给你总结。
GitLab 对 Debian 版本要求严格:
| GitLab 版本 | 推荐 Debian |
|---|---|
| GitLab 16+ | Debian 11 / 12 |
| GitLab 15 | Debian 10 / 11 |
✅ 推荐:Debian 12 (bookworm)
❌ 不推荐:Debian 9 / 旧系统
检查:
cat /etc/os-release
GitLab 非常吃资源:
| 规模 | CPU | 内存 |
|---|---|---|
| 测试 | 2核 | 4G |
| 小团队 | 4核 | 8G |
| 正式使用 | 8核 | 16G+ |
⚠️ 内存 < 4G 基本跑不动(会 OOM)
查看内存:
free -h
GitLab 默认占用:
如果你已有:
⚠️ 会直接冲突
解决方式:
sudo apt update
sudo apt install -y curl openssh-server ca-certificates tzdata perl
curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/setup.sh | sudo bash
sudo EXTERNAL_URL="https://gitlab.example.com" apt install gitlab-ce
安装完:
sudo gitlab-ctl reconfigure
sudo gitlab-rake "gitlab:password:reset[root]"
编辑:
sudo nano /etc/gitlab/gitlab.rb
external_url 'https://gitlab.example.com'
然后:
sudo gitlab-ctl reconfigure
放行:
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 22
云服务器还要开安全组
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
❌ 用 Docker 但不映射 volume → 数据全丢
❌ 内存太小 → 502 / 500
❌ 改了 SSH 端口但 GitLab 没改
❌ 没备份就升级
❌ 用 root 跑 GitLab(本身没问题,但服务器不安全)
sudo gitlab-rake gitlab:backup:create
不能跨大版本升级
15 → 16 → 17
如果你愿意,可以告诉我:
我可以直接给你一份可直接用的配置。