Debian 上 GitLab 卡顿,通常不是“GitLab 本身慢”,而是资源、配置或存储出了问题。下面按「先快后慢、先免费后花钱」的顺序给你一套排查与解决思路。
在 Debian 上执行:
top
free -h
df -h
iostat -x 1 # 需安装 sysstat
重点看:
GitLab 官方建议:
free -h
如果没有 swap:
dd if=/dev/zero of=/swapfile bs=1M count=4096
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
写入开机挂载:
echo '/swapfile none swap sw 0 0' >> /etc/fstab
编辑:
sudo vim /etc/gitlab/gitlab.rb
如果你只是代码托管(不用 CI / Pages / Registry):
gitlab_rails['registry_enabled'] = false
pages_nginx['enable'] = false
prometheus['enable'] = false
alertmanager['enable'] = false
然后:
sudo gitlab-ctl reconfigure
新版 GitLab 用 Puma:
puma['worker_processes'] = 2
puma['worker_timeout'] = 60
老版本(Unicorn):
unicorn['worker_processes'] = 2
然后:
gitlab-ctl reconfigure
gitlab-ctl restart
sidekiq['concurrency'] = 10
postgresql['shared_buffers'] = "512MB"
GitLab 对磁盘 IO 非常敏感:
如果是云服务器:
du -sh /var/log/gitlab
清理:
gitlab-ctl logrotate
或定时:
0 3 * * * /opt/gitlab/bin/gitlab-ctl logrotate
nginx['enable'] = false
然后用你自己的 Nginx + proxy_pass。
nginx['gzip_enabled'] = true
卡顿常见原因:
解决:
deploy:
resources:
limits:
memory: 4g
如果现在就很卡:
gitlab-ctl stop
free -h
swapon -a
gitlab-ctl start
| 用户规模 | 内存 | CPU |
|---|---|---|
| 1–10人 | 4GB | 2核 |
| 10–50人 | 8GB | 4核 |
| 50+ | 16GB+ | 8核 |
你可以告诉我:
我可以直接给你一份可复制的 gitlab.rb 配置。