GitLab 对系统资源要求较高,内存占用高是常见问题。下面按“先诊断 → 再优化 → 最后兜底”的思路给你一套实用方案,适用于 Omnibus GitLab(最常见)。
在 GitLab 服务器上执行:
free -h
top
htop
重点看:
⚠️ GitLab 官方推荐最低配置:
编辑:
sudo vim /etc/gitlab/gitlab.rb
puma['worker_processes'] = 2 # 原来可能是 4 或更高
puma['per_worker_max_memory_mb'] = 1024
sidekiq['max_concurrency'] = 10 # 默认 50
应用配置:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
Gitaly 是 GitLab 的 Git 后端,非常吃内存。
gitaly['concurrency'] = [
{
"rpc" => "/gitaly.SmartHTTPService/PostReceivePack",
"max_per_repo" => 1
}
]
如果你只是自用 GitLab,可以直接关掉监控。
prometheus_monitoring['enable'] = false
如果你只用 Git + CI,不需要这些:
gitlab_pages['enable'] = false
gitlab_kas['enable'] = false
grafana['enable'] = false
在 GitLab Web 后台:
即使内存够,也建议有 Swap:
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
写入 fstab:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
sudo sysctl vm.overcommit_memory=1
写入:
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
echo "vm.overcommit_memory=1" | sudo tee -a /etc/sysctl.conf
如果只是代码托管:
内存占用:
| 工具 | 内存 |
|---|---|
| GitLab | 4–16 GB |
| Gitea | 100–300 MB |
puma['worker_processes'] = 2
sidekiq['max_concurrency'] = 10
prometheus_monitoring['enable'] = false
gitlab_pages['enable'] = false
grafana['enable'] = false
gitlab_kas['enable'] = false
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
你可以直接贴:
free -htop 前 20 行我可以帮你 精确算最低内存 & 给出最优配置。