在 Debian 系统上优化 GitLab,核心目标是在保证服务稳定的前提下,降低资源占用、提升响应速度。下面从 系统、GitLab 配置、数据库、存储、缓存、监控 等方面给你一套实用优化方案。
GitLab 官方建议:
| 用户数 | CPU | 内存 |
|---|---|---|
| < 100 | 2 核 | 4 GB |
| 100–500 | 4 核 | 8 GB |
| > 500 | 8 核+ | 16 GB+ |
⚠️ 内存 < 4GB 体验会很差
systemctl disable bluetooth
systemctl disable cups
systemctl disable avahi-daemon
echo "fs.file-max = 100000" >> /etc/sysctl.conf
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
sysctl -p
编辑配置文件:
vim /etc/gitlab/gitlab.rb
# 减少 Puma(GitLab Web)
puma['worker_processes'] = 2
puma['min_threads'] = 2
puma['max_threads'] = 4
# 减少 Sidekiq(后台任务)
sidekiq['max_concurrency'] = 10
默认配置很高,小机器会直接卡死
gitlab_rails['gitlab_email_enabled'] = false
gitlab_rails['usage_ping_enabled'] = false
gitlab_rails['sentry_enabled'] = false
# 不使用 GitLab CI Runner
gitlab_ci['runner_token'] = nil
如果你 不用容器镜像库:
gitlab_rails['registry_enabled'] = false
如果你的服务器内存 < 8GB:
prometheus_monitoring['enable'] = false
postgresql['shared_buffers'] = "256MB"
postgresql['work_mem'] = "8MB"
postgresql['maintenance_work_mem'] = "32MB"
postgresql['max_worker_processes'] = 2
GitLab 对磁盘 IO 非常敏感。
git_data_dirs({
"default" => {
"path" => "/data/gitlab/git-data"
}
})
gitaly['configuration'] = {
storage: [
{
name: "default",
path: "/var/opt/gitlab/git-data/repositories"
}
]
}
默认已启用,无需额外配置
可检查:
gitlab-rails console
> Redis.new.info
# 重新加载配置
gitlab-ctl reconfigure
# 重启服务
gitlab-ctl restart
# 查看资源占用
gitlab-ctl status
htop
gitlab-ctl tail gitlab-rails
gitlab-rails console
> Sidekiq::Queue.new.size
puma['worker_processes'] = 2
sidekiq['max_concurrency'] = 8
postgresql['shared_buffers'] = "256MB"
prometheus_monitoring['enable'] = false
gitlab_rails['registry_enabled'] = false
✅ 推荐替代方案
如果你愿意,可以告诉我:
我可以给你一套 完全定制的 GitLab 优化配置。