在 Linux 上配置 GitLab 时,确实有一些实用技巧和常见坑点,下面按「安装 → 性能 → 安全 → 日常维护」给你一个比较系统的总结,适合生产环境。
Omnibus 包(官方推荐)
# Ubuntu / Debian
curl -fsSL https://packages.gitlab.com/gpg.key | sudo apt-key add -
sudo apt-get install -y gitlab-ee # 或 gitlab-ce
# CentOS / RHEL
sudo yum install -y gitlab-ee
✅ 优点:
/etc/gitlab/gitlab.rb)❌ 不推荐:
gitlab.rb 必调的核心配置GitLab 的“技巧”90% 都在 gitlab.rb 里。
external_url 'https://gitlab.example.com'
⚠️ 改完后必须执行:
gitlab-ctl reconfigure
如果只做 Git + CI,不需要全部组件:
gitlab_rails['monitoring_enabled'] = false
prometheus_monitoring['enable'] = false
grafana['enable'] = false
postgresql['shared_buffers'] = "512MB"
postgresql['max_connections'] = 200
redis['maxmemory'] = "512mb"
redis['maxmemory_policy'] = "allkeys-lru"
sidekiq['concurrency'] = 10
CPU 强可适当提高,否则建议 5–10
推荐:
ext4 / xfs
挂载参数(示例):
noatime,nodiratime,data=ordered
sudo swapoff -a
并在 /etc/fstab 中注释 swap 行
cat >> /etc/security/limits.conf <<EOF
* soft nofile 65536
* hard nofile 65536
EOF
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']
⚠️ 80 端口必须可访问
nginx['ssl_certificate'] = "/etc/gitlab/ssl/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/privkey.pem"
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
sudo apt install gitlab-runner
gitlab-runner register
✅ 技巧:
shelldockerprivileged=truegitlab-rake gitlab:backup:create
默认路径:
/var/opt/gitlab/backups/
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
✅ 正确顺序:
gitlab-ctl stop puma
gitlab-ctl stop sidekiq
apt upgrade gitlab-ee
gitlab-ctl reconfigure
gitlab-ctl restart
⚠️ 不要跳大版本(如 15 → 17)
| 问题 | 解决 |
|---|---|
| 502 错误 | 内存不足 / puma 未启动 |
| git clone 慢 | 调整 ssh / http 并发 |
| 磁盘暴涨 | artifacts / registry 未清理 |
| 邮件发不出去 | 检查 SMTP + 防火墙 |
| 用户规模 | CPU | 内存 |
|---|---|---|
| 10 人 | 2 核 | 4 GB |
| 50 人 | 4 核 | 8 GB |
| 200+ | 8 核 | 16 GB+ |
如果你愿意,我可以帮你:
gitlab.rb 模板你可以直接说:
“我的是 Ubuntu 22.04,8G 内存,50 人用,怎么配?”