在 CentOS 上优化 GitLab,一般从 系统资源、GitLab 配置、数据库、缓存、存储、网络、备份 几个方面入手。下面给你一份实用优化清单(以 GitLab Omnibus 安装为主)。
编辑 /etc/sysctl.conf:
# 文件句柄
fs.file-max = 655360
# 网络
net.core.somaxconn = 1024
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_tw_reuse = 1
执行:
sysctl -p
/etc/security/limits.conf:
* soft nofile 65536
* hard nofile 65536
systemctl disable firewalld --now # 若用安全组可关
systemctl disable postfix
配置文件:
/etc/gitlab/gitlab.rb
unicorn['worker_processes'] = 2
unicorn['worker_memory_limit_min'] = "200MB"
unicorn['worker_memory_limit_max'] = "300MB"
sidekiq['concurrency'] = 10
unicorn['worker_processes'] = 4
sidekiq['concurrency'] = 15
unicorn['worker_processes'] = 8
sidekiq['concurrency'] = 25
应用配置:
gitlab-ctl reconfigure
postgresql['shared_buffers'] = "256MB" # 内存的 25%
postgresql['max_connections'] = 200
postgresql['work_mem'] = "8MB"
postgresql['shared_buffers'] = "4GB"
postgresql['effective_cache_size'] = "8GB"
redis['enable'] = false
gitlab_rails['redis_host'] = "127.0.0.1"
gitlab_rails['redis_port'] = 6379
gitlab_rails['redis_cache_instance'] = "redis://127.0.0.1:6379/1"
GitLab 对 IO 非常敏感
git_data_dirs({
"default" => { "path" => "/data/gitlab/git-data" }
})
gitlab-rake gitlab:cleanup:project_uploads
gitlab-rake gitlab:db:clean_status
nginx['enable'] = true
nginx['gzip'] = "on"
nginx['gzip_comp_level'] = "2"
nginx['worker_processes'] = 4
nginx['worker_connections'] = 10240
prometheus['enable'] = true
grafana['enable'] = true
访问:
http://gitlab_ip/-/grafana
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
gitlab_rails['backup_keep_time'] = 604800
gitlab-ctl top
gitlab-ctl tail
gitlab-rake gitlab:check
| 用户数 | CPU | 内存 |
|---|---|---|
| <50 | 2 | 4G |
| 50–200 | 4 | 8G |
| 200+ | 8 | 16G+ |
如果你愿意,可以告诉我:
我可以直接帮你 定制一份 gitlab.rb 优化配置。