在 CentOS 上优化 GitLab,通常从 系统资源、GitLab 配置、数据库、存储、网络、安全与维护 几个方面入手。下面给你一套实用、可落地的优化方案,适用于 GitLab CE / EE(Omnibus 安装)。
编辑:
vi /etc/security/limits.conf
添加:
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
立即生效:
ulimit -n 65535
减少系统负载:
systemctl disable firewalld --now # 若使用云安全组
systemctl disable postfix --now # 不用邮件可关
✅ 推荐:
/boot查看:
df -Th
GitLab 配置文件:
/etc/gitlab/gitlab.rb
puma['worker_processes'] = 2
puma['min_threads'] = 4
puma['max_threads'] = 8
sidekiq['max_concurrency'] = 10
内存小(≤8G)建议:
gitlab_rails['gitlab_email_enabled'] = false
prometheus_monitoring['enable'] = false
grafana['enable'] = false
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['git_max_size'] = 209715200 # 200MB
postgresql['shared_buffers'] = "512MB"
postgresql['work_mem'] = "16MB"
postgresql['maintenance_work_mem'] = "128MB"
postgresql['effective_cache_size'] = "2GB"
根据内存调整(示例为 8G 服务器)
gitlab-rake gitlab:db:cleanup
gitlab-rake gitlab:env:info
gitlab_rails['gitlab_shell_git_timeout'] = 800
清理历史大文件(推荐工具):
git filter-repo
✅ 强烈建议:
/var/opt/gitlab/var/opt/gitlab/git-datanginx['worker_processes'] = 2
nginx['worker_connections'] = 1024
nginx['keepalive_timeout'] = 65
nginx['gzip'] = "on"
nginx['gzip_http_version'] = "1.1"
nginx['gzip_comp_level'] = "2"
redis['maxmemory'] = "512mb"
redis['maxmemory_policy'] = "allkeys-lru"
gitlab_rails['application_settings_cache_seconds'] = 60
gitlab-ctl tail
gitlab-rake gitlab:cleanup:logs
gitlab-rake gitlab:cleanup:orphan_job_artifacts
gitlab-rake gitlab:cleanup:orphan_lfs_files
✅ 长期支持版本(推荐):
yum update gitlab-ce
gitlab-ctl reconfigure
| 内存 | 配置建议 |
|---|---|
| 4G | 单 Puma worker,关闭 Prometheus |
| 8G | 2 Puma workers,Sidekiq ≤ 10 |
| 16G+ | 默认配置即可 |
gitlab-ctl status
gitlab-rake gitlab:check
htop
free -h
CentOS GitLab 优化 = 限制并发 + 精简服务 + 数据库调优 + SSD + 定期维护
如果你愿意,可以告诉我:
我可以给你一份 定制版 gitlab.rb 配置。