Linux 上的 GitLab 卡顿通常由 资源不足、配置不合理或访问量大 导致。可以从 服务器资源、GitLab 配置、访问方式、系统层面 四个方向排查和优化。
top
htop
free -h
df -h
重点看:
✅ GitLab 官方最低要求:
GitLab 非常吃内存(gitlab-rails、sidekiq、gitaly 等)。
sync && echo 3 > /proc/sys/vm/drop_caches
编辑 GitLab 配置:
vim /etc/gitlab/gitlab.rb
限制部分服务内存(示例):
sidekiq['max_concurrency'] = 10
gitlab_rails['env'] = {
'MALLOC_ARENA_MAX' => '2'
}
然后:
gitlab-ctl reconfigure
gitlab-ctl restart
GitLab 13+ 默认使用 Puma
puma['worker_processes'] = 2 # 根据 CPU 核数调整
puma['min_threads'] = 1
puma['max_threads'] = 2
4 核 8G 建议 worker = 2~3
Gitaly 负责 Git 操作,仓库多时很吃资源。
gitaly['concurrency'] = [
{ "rpc" => "GetTreeEntries", "max" => 5 }
]
查看队列:
gitlab-ctl tail sidekiq
重启 Sidekiq:
gitlab-ctl restart sidekiq
检查慢查询:
gitlab-ctl pg-ctl status
优化:
postgresql['shared_buffers'] = "512MB"
postgresql['max_connections'] = 200
iostat -x 1
/var/opt/gitlab 在机械盘swapoff -a
git clone --depth=1
gitlab_ci['max_active_pipelines'] = 10
ulimit -n
建议:
echo "fs.file-max = 100000" >> /etc/sysctl.conf
sysctl -p
gitlab-ctl status
关闭不需要的组件(如 Mattermost、Prometheus):
mattermost['enable'] = false
prometheus_monitoring['enable'] = false
✅ 内存 ≥ 8G
✅ CPU ≥ 4 核
✅ 磁盘不是机械盘
✅ Puma worker 不过高
✅ 没有大量 CI 并发
✅ 没有 swap 被大量使用
你可以把下面信息发我,我可以帮你精确定位:
top 或 htop 截图我可以直接给你 一份针对你环境的 gitlab.rb 优化配置。