在 CentOS 上优化 GitLab,通常从系统资源、GitLab 自身配置、数据库与缓存、存储与网络、日常维护几个方面入手。下面给你一套实用优化清单(适用于 GitLab CE/EE,CentOS 7/8)。
systemctl disable --now postfix
systemctl disable --now firewalld # 如有外部防火墙可关
(保留必要安全策略)
编辑 /etc/sysctl.conf:
net.core.somaxconn = 1024
net.ipv4.tcp_max_syn_backlog = 8192
vm.swappiness = 10
执行:
sysctl -p
ulimit -n 65535
在 /etc/security/limits.conf:
* soft nofile 65535
* hard nofile 65535
配置文件:/etc/gitlab/gitlab.rb
示例(4G 内存):
puma['worker_processes'] = 2
puma['worker_timeout'] = 60
sidekiq['concurrency'] = 10
8G 以上:
puma['worker_processes'] = 4
sidekiq['concurrency'] = 20
修改后:
gitlab-ctl reconfigure
gitlab-ctl restart
postgresql['shared_buffers'] = "512MB"
postgresql['max_connections'] = 200
redis['maxmemory'] = "512mb"
redis['maxmemory_policy'] = "allkeys-lru"
git_data_dirs({
"default" => {
"path" => "/data/gitlab/git-data"
}
})
gitaly['configuration'] = {
concurrency: {
'rpc' => 16
}
}
nginx['enable'] = true
nginx['client_max_body_size'] = '250m'
前端用 Nginx / Caddy,关闭 GitLab 自带 Nginx:
nginx['enable'] = false
gitlab-rake gitlab:cleanup:orphan_job_artifact_files
gitlab-rake gitlab:cleanup:project_uploads
gitlab_rails['backup_keep_time'] = 604800
gitlab-ctl status
gitlab-rails console
top -c
df -h
推荐开启:
| 规模 | CPU | 内存 |
|---|---|---|
| 小团队 | 2核 | 4G |
| 中型 | 4核 | 8G |
| 企业 | 8核+ | 16G+ |
如果你愿意,可以告诉我:
我可以给你针对性配置文件。