GitLab 在 Linux 上的优化,通常可以从 系统资源、GitLab 配置、数据库、存储、网络、日常维护 这几个维度来做。下面给你一套比较完整的优化思路(适合自建 GitLab,社区版 / 企业版都适用)。
GitLab 非常吃内存,官方建议至少 8GB,生产环境 16GB+。
检查内存:
free -h
调整 swap(避免 OOM):
swapon -s
建议:
ulimit -n
建议设置为:
65535
编辑:
/etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
配置文件:
/etc/gitlab/gitlab.rb
修改后务必执行:
gitlab-ctl reconfigure
puma['worker_processes'] = 2
puma['min_threads'] = 1
puma['max_threads'] = 2
默认是 CPU 核数,非常吃内存。
sidekiq['max_concurrency'] = 10
如果你只用 Git + CI:
gitlab_rails['monitoring_whitelist'] = []
prometheus_monitoring['enable'] = false
grafana['enable'] = false
自建 GitLab 时,建议:
shared_buffers = 2GB
work_mem = 16MB
maintenance_work_mem = 512MB
effective_cache_size = 6GB
gitlab-rake gitlab:db:cleanup
迁移仓库目录:
git_data_dirs({
"default" => { "path" => "/data/gitlab/git-data" }
})
gitlab-rake gitlab:cleanup:orphan_lfs_files
gitlab-rake gitlab:cleanup:project_uploads
gitlab_rails['max_attachment_size'] = 100
gitlab_rails['max_import_size'] = 200
gitlab-runner register
不要和 GitLab 同机。
concurrent = 2
cache:
paths:
- node_modules/
GitLab 自带 Nginx,可开启:
nginx['enable'] = true
nginx['client_max_body_size'] = '200m'
nginx['redirect_http_to_https'] = true
gitlab-ctl tail
du -sh /var/log/gitlab
清理:
gitlab-ctl clean-logs
apt update
apt upgrade gitlab-ee
gitlab-ctl status
top
htop
iostat -x 1
重点关注:
puma['worker_processes'] = 2
sidekiq['max_concurrency'] = 10
prometheus_monitoring['enable'] = false
grafana['enable'] = false
gitlab_rails['monitoring_whitelist'] = []
如果你愿意,可以告诉我:
我可以给你针对性的优化方案。