在 CentOS 上部署和运维 GitLab 时,调优主要涉及系统层面、GitLab 自身配置、数据库与缓存、存储与网络几个方面。下面给你一份比较实用的 GitLab 调优指南(适用于 Omnibus 版 GitLab)。
编辑 /etc/sysctl.conf 或 /etc/sysctl.d/gitlab.conf:
# 文件句柄数
fs.file-max = 1000000
# 网络连接
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 4096
# TCP
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
# 内存
vm.swappiness = 10
vm.overcommit_memory = 1
执行:
sysctl -p
/etc/security/limits.conf:
* soft nofile 1000000
* hard nofile 1000000
GitLab 主要吃内存的服务:
unicorn / puma(Web)sidekiq(后台任务)postgresqlredisgitaly配置文件:
/etc/gitlab/gitlab.rb
修改后执行:
gitlab-ctl reconfigure
puma['worker_processes'] = 4
puma['min_threads'] = 4
puma['max_threads'] = 16
经验值:
sidekiq['concurrency'] = 20
如任务多(CI 频繁):
sidekiq['concurrency'] = 30
postgresql['shared_buffers'] = "2GB"
postgresql['work_mem'] = "32MB"
postgresql['maintenance_work_mem'] = "512MB"
postgresql['max_connections'] = 200
内存建议:
redis['maxmemory'] = "1gb"
redis['maxmemory_policy'] = "allkeys-lru"
gitaly['concurrency'] = [
{ "rpc" => "GetTreeEntries", "max_per_repo" => 20 },
{ "rpc" => "ListFiles", "max_per_repo" => 20 }
]
如果不需要某些功能:
prometheus['enable'] = false
grafana['enable'] = false
gitlab_rails['monitoring_whitelist'] = []
concurrent = 10
GitLab 对磁盘 IO 非常敏感,尤其是:
git_data_dirs({
"default" => { "path" => "/data/gitlab/git-data" }
})
gitlab-rake gitlab:cleanup:orphan_job_artifact_files
gitlab-rake gitlab:cleanup:project_uploads
logging['logrotate_frequency'] = "daily"
logging['logrotate_rotate'] = 14
gitlab-ctl top
gitlab-ctl status
| 规模 | CPU | 内存 |
|---|---|---|
| 小型团队 | 2 | 4GB |
| 中型 | 4 | 8GB |
| 大型 | 8+ | 16GB+ |
如果你愿意,可以告诉我:
我可以帮你直接给出一份可用的 gitlab.rb 配置。