在 Linux 上部署和配置 GitLab(通常指 GitLab CE/EE 自托管),有不少“坑”和最佳实践。下面从安装前、安装中、安装后、安全与运维几个维度给你梳理一下注意事项。
GitLab 比较吃资源,官方最低要求:
⚠️ 内存小于 4G 很容易出现 502 / 卡死。
推荐:
✅ 用 LTS 版本,避免系统太新导致依赖不兼容。
gitlab.example.com)sudo apt update
sudo apt install -y curl openssh-server ca-certificates
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo EXTERNAL_URL="https://gitlab.example.com" apt install gitlab-ee
优点:
❌ 不推荐:
gitlab.rb)配置文件路径:
/etc/gitlab/gitlab.rb
external_url 'https://gitlab.example.com'
⚠️ 一旦修改,要执行:
gitlab-ctl reconfigure
否则无法注册、找回密码:
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.example.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "gitlab@example.com"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'
改完执行:
gitlab-ctl reconfigure
gitlab-rake gitlab:email:test
GitLab 自带 Let’s Encrypt:
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
或自己放证书:
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.key"
gitlab_rails['gitlab_signup_enabled'] = false
只开放:
ufw allow 22,80,443/tcp
GitLab 自带备份:
gitlab-rake gitlab:backup:create
建议:
| 问题 | 原因 |
|---|---|
| 502 错误 | 内存不足 / 服务未启动 |
| 邮箱收不到 | SMTP 没配 |
| 改域名后异常 | 没 reconfigure |
| 磁盘爆满 | 没清理备份 / CI 缓存 |
| 登录慢 | PostgreSQL 性能问题 |
gitlab-ctl status
gitlab-ctl restart
gitlab-ctl tail
gitlab-rake gitlab:check
如果你是:
如果你愿意,可以告诉我:
我可以给你一套可直接用的配置模板。