在 CentOS 上优化 GitLab,通常从 系统资源、GitLab 组件、数据库、存储、网络、安全 六个方面入手。以下是一套生产环境可用的优化方案。
编辑:
vi /etc/security/limits.conf
添加:
* soft nofile 65535
* hard nofile 65535
立即生效:
ulimit -n 65535
GitLab 对内存敏感,Swap 会导致性能下降:
swapoff -a
永久关闭(注释 /etc/fstab 中的 swap 行)。
编辑:
vi /etc/sysctl.conf
添加:
vm.swappiness = 1
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.ip_local_port_range = 1024 65535
生效:
sysctl -p
vi /etc/gitlab/gitlab.rb
gitlab_pages['enable'] = false
grafana['enable'] = false
prometheus_monitoring['enable'] = false
puma['enable'] = true
puma['worker_processes'] = 2 # 建议 = CPU 核数
puma['min_threads'] = 4
puma['max_threads'] = 8
unicorn['worker_processes'] = 2
⚠️ 不要设置过大,否则内存会爆
sidekiq['max_concurrency'] = 10
gitlab_rails['db_pool'] = 20
gitlab-ctl reconfigure
gitlab-ctl restart
避免外部数据库带来的网络开销。
postgresql['max_connections'] = 200
postgresql['shared_buffers'] = "512MB"
postgresql['work_mem'] = "16MB"
GitLab 对磁盘 IO 很敏感。
git_data_dirs({
"default" => { "path" => "/data/gitlab/git-data" }
})
确保 /data 是 SSD 或高性能磁盘。
gitlab-rake gitlab:cleanup:orphan_lfs_files
puma['worker_processes'] = 1
sidekiq['max_concurrency'] = 5
prometheus_monitoring['enable'] = false
gitlab-ctl status
free -h
nginx['enable'] = true
nginx['worker_processes'] = 2
letsencrypt['enable'] = true
gitlab-rake cache:clear
gitlab-rake gitlab:check
| 用户规模 | CPU | 内存 | 磁盘 |
|---|---|---|---|
| 10–50 人 | 2 核 | 4GB | SSD 40GB |
| 50–200 人 | 4 核 | 8GB | SSD 100GB |
| 200+ | 8 核 | 16GB+ | SSD + 分离存储 |
top
gitlab-ctl tail
gitlab-ctl status puma
如果你愿意,可以告诉我:
我可以 直接给你一份定制化的 gitlab.rb 配置。