在 Linux 服务器上 GitLab 卡顿,通常不是单一原因,需要从 资源、配置、使用方式 三个层面排查。下面给你一套实用排查 + 优化方案,从最常见到进阶。
top
htop
free -h
df -h
重点看:
wa 高)✅ GitLab 非常吃内存:
gitlab-ctl status
gitlab-ctl tail
如果有服务频繁重启或报错,卡顿是必然的。
编辑配置:
vim /etc/gitlab/gitlab.rb
关闭或限制组件:
# 减少 Sidekiq 并发
sidekiq['concurrency'] = 5
# 限制 unicorn / puma
puma['worker_processes'] = 2
puma['min_threads'] = 1
puma['max_threads'] = 2
# 禁用不需要的服务
prometheus_monitoring['enable'] = false
grafana['enable'] = false
然后:
gitlab-ctl reconfigure
gitlab-ctl restart
gitlab_ci['job_timeout'] = 3600
或限制 Runner 并发:
# runner config.toml
concurrent = 2
iostat -x 1
如果 %util 接近 100%,说明磁盘扛不住。
gitlab-psql
postgresql['shared_buffers'] = "512MB"
postgresql['max_connections'] = 100
老版本性能差、Bug 多。
apt update
apt upgrade gitlab-ee # 或 gitlab-ce
⚠️ 升级前一定备份:
gitlab-backup create
ulimit -n 65535
写入:
vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
通常是:
gitlab-ctl restart puma
| 项目 | 建议 |
|---|---|
| 内存 | ≥ 16GB |
| CPU | ≥ 4 核 |
| 磁盘 | SSD |
| 并发 | 限制 Puma / Sidekiq |
| 版本 | 保持最新 |
你可以直接贴出:
top 或 htop 截图我可以 直接给你一套针对你服务器的优化参数 ✅