在 Debian 上“优化 GitLab”通常可以从系统资源、GitLab 自身配置、数据库与缓存、存储与备份、网络与安全几个方面入手。下面给出一套比较实用、可落地的优化方案。
编辑 /etc/sysctl.conf:
vm.swappiness=10
net.core.somaxconn=1024
fs.file-max=65535
应用:
sysctl -p
编辑 /etc/security/limits.conf:
gitlab soft nofile 65535
gitlab hard nofile 65535
配置文件位置:
/etc/gitlab/gitlab.rb
修改后执行:
gitlab-ctl reconfigure
puma['worker_processes'] = 4
puma['worker_timeout'] = 60
(老版本 GitLab 用 unicorn)
sidekiq['concurrency'] = 10
如果不用部分功能:
registry['enable'] = false
grafana['enable'] = false
prometheus['enable'] = false
postgresql['shared_buffers'] = "2GB"
postgresql['work_mem'] = "16MB"
postgresql['max_connections'] = 200
(按内存调整,一般 shared_buffers = 内存 * 25%)
redis['maxmemory'] = "1gb"
redis['maxmemory_policy'] = "allkeys-lru"
gitlab-ci 的 cache 和 artifactsgit_data_dirs({
"default" => { "path" => "/data/gitlab/git-data" }
})
gitlab-rake gitlab:cleanup:project_uploads
gitlab-rake cache:clear
gitlab_rails['backup_keep_time'] = 604800
手动:
gitlab-rake gitlab:backup:create
gitlab-ctl status
gitlab-rails console
gitlab-rake gitlab:env:info
也可启用 Prometheus + Grafana(资源充足时)
如果 Debian 机器配置很低(<4GB):
puma['worker_processes'] = 2
sidekiq['concurrency'] = 5
postgresql['shared_buffers'] = "1GB"
redis['maxmemory'] = "512mb"
registry['enable'] = false
grafana['enable'] = false
prometheus['enable'] = false
如果你愿意,可以告诉我:
我可以直接给你一份可复制的 gitlab.rb 优化配置。