在 Linux 上运行 GitLab(尤其是自建 GitLab CE/EE)时,调优主要从 系统层面、GitLab 自身配置、数据库与缓存、存储与网络、监控 几个方面入手。下面给你一套比较实用的调优思路。
GitLab 比较吃内存,建议:
free -h
sysctl vm.swappiness=10
GitLab 会大量使用文件句柄:
ulimit -n
建议设置为:
* soft nofile 65536
* hard nofile 65536
sysctl -w net.core.somaxconn=1024
sysctl -w net.ipv4.tcp_max_syn_backlog=8192
配置文件位置:
/etc/gitlab/gitlab.rb
修改后执行:
gitlab-ctl reconfigure
gitlab-ctl restart
GitLab 包含很多服务,可按需关闭或限制。
GitLab 13+ 默认是 Puma
puma['worker_processes'] = 4
puma['min_threads'] = 4
puma['max_threads'] = 16
规则:
sidekiq['concurrency'] = 10
小服务器可降到 5–8。
如果是代码托管为主:
prometheus_monitoring['enable'] = false
grafana['enable'] = false
mattermost['enable'] = false
registry['enable'] = false
pages['enable'] = false
postgresql['shared_buffers'] = "2GB"
postgresql['work_mem'] = "32MB"
postgresql['max_connections'] = 200
经验:
GitLab 默认内置 Redis,如果压力大可:
redis['maxmemory'] = "1gb"
redis['maxmemory_policy'] = "allkeys-lru"
GitLab 对磁盘 IO 非常敏感。
git_data_dirs({
"default" => { "path" => "/data/gitlab/git-data" }
})
gitlab-rake gitlab:cleanup:orphan_job_artifacts
gitlab-rake gitlab:cleanup:project_uploads
gitlab_ci['concurrent'] = 4
gitlab_rails['gitlab_default_projects_features_issues'] = false
gitlab_rails['gitlab_default_projects_features_merge_requests'] = false
gitlab-ctl top
htop
iostat -x 1
gitlab-ctl tail nginx
gitlab-ctl tail puma
| 问题 | 原因 | 解决 |
|---|---|---|
| 页面卡 | Puma 太少 | 增加 worker |
| 502 | 内存不足 | 减组件 / 加内存 |
| git clone 慢 | 磁盘 IO | SSD |
| Sidekiq 堆积 | 并发低 | 提高 concurrency |
| CPU 高 | 监控服务 | 关 Prometheus |
puma['worker_processes'] = 4
sidekiq['concurrency'] = 10
postgresql['shared_buffers'] = "2GB"
prometheus_monitoring['enable'] = false
grafana['enable'] = false
如果你愿意,可以告诉我:
我可以帮你 直接给出一份可直接用的 gitlab.rb 配置。