解决 CentOS 上 GitLab 卡顿的问题,通常需要从系统资源、GitLab 配置、数据库、存储、网络等多个维度进行排查和优化。GitLab 本身是一个资源消耗较大的应用,尤其在运行时涉及 Ruby on Rails、PostgreSQL、Redis、Sidekiq、Gitaly 等多个组件。
下面是系统性排查和优化建议,按由易到难、由常见到少见的顺序来。
top
htop
free -h
df -h
重点关注:
✅ 最低推荐配置(GitLab 官方):
GitLab 会同时运行:
free -h
限制并发进程数(最立竿见影)
编辑:
vim /etc/gitlab/gitlab.rb
puma['worker_processes'] = 2
puma['min_threads'] = 1
puma['max_threads'] = 2
(如果是老版本 GitLab)
unicorn['worker_processes'] = 2
sidekiq['max_concurrency'] = 10
prometheus_monitoring['enable'] = false
gitlab-ctl reconfigure
gitlab-ctl restart
gitlab-rails dbconsole
postgresql['shared_buffers'] = "512MB"
postgresql['max_connections'] = 100
postgresql['work_mem'] = "16MB"
应用:
gitlab-ctl reconfigure
gitlab-ctl restart postgresql
Gitaly 是 GitLab 的 Git 核心服务,配置不当会严重卡顿。
gitaly['concurrency'] = [
{
"rpc" => "/gitaly.SmartHTTPService/PostReceivePack",
"max_per_repo" => 2
}
]
检查磁盘 IO:
iostat -x 1
git_data_dirs({
"default" => {
"path" => "/data/gitlab/git-data"
}
})
然后执行:
gitlab-ctl reconfigure
gitlab-ctl restart
老版本 GitLab 性能问题常见。
查看版本:
gitlab-rake gitlab:env:info
建议:
gitlab-rake gitlab:check
gitlab-rake gitlab:doctor:git
gitlab-ctl tail
gitlab-ctl tail sidekiq
gitlab-ctl tail puma
gitlab_ci['runner_capacity'] = 2
✅ 内存 ≥ 8GB
✅ Puma / Sidekiq 并发已限制
✅ 磁盘是 SSD
✅ Prometheus 已关闭
✅ GitLab 不是特别老版本
✅ 没有 swap 颠簸
你可以直接贴出以下信息,我可以精准定位卡顿原因:
top 或 htop 截图我可以直接给你一套适合你服务器的 gitlab.rb 配置。