下面从 系统层、GitLab 自身、数据库与缓存、存储与网络、日常维护 几个方面,系统讲一下 Debian 上 GitLab 的优化实践。
uname -a
cat /etc/debian_version
systemctl list-unit-files --type=service | grep enabled
关闭如:
bluetoothcupsavahi-daemonulimit -n
建议 ≥ 65535
/etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
/etc/sysctl.conf
net.core.somaxconn = 1024
net.ipv4.tcp_max_syn_backlog = 8192
vm.swappiness = 10
sysctl -p
gitlab-rake gitlab:env:info
编辑:
/etc/gitlab/gitlab.rb
puma['worker_processes'] = 4
puma['worker_timeout'] = 60
puma['max_threads'] = 16
经验公式:
worker_processes = CPU核数
max_threads = 8~16
sidekiq['concurrency'] = 20
gitlab_rails['lfs_enabled'] = false # 不用 LFS 可关
grafana['enable'] = false
prometheus['enable'] = false
postgresql['shared_buffers'] = "2GB"
postgresql['max_connections'] = 200
建议:
shared_buffers = 25% RAMredis['maxmemory'] = "1gb"
redis['maxmemory_policy'] = "allkeys-lru"
git_data_dirs({
"default" => "/data/gitlab/git-data"
})
gitlab-rake gitlab:cleanup:project_uploads
gitlab-rake cache:clear
GitLab 自带 Nginx,建议:
nginx['worker_processes'] = 4
nginx['keepalive_timeout'] = 65
nginx['ssl_protocols'] = "TLSv1.2 TLSv1.3"
gitlab-rake gitlab:check
/var/log/gitlab
使用 logrotate
gitlab-rake gitlab:backup:create
| 规模 | CPU | 内存 |
|---|---|---|
| 小团队 | 2 | 4G |
| 中型 | 4 | 8G |
| 大型 | 8+ | 16G+ |
top
htop
gitlab-ctl status
gitlab-ctl tail
重点看:
pumasidekiqpostgresql如果你愿意,可以告诉我:
我可以给你 一份直接可用的 gitlab.rb 配置。