温馨提示×

centos gitlab怎么优化

小樊
37
2026-09-06 00:10:28
栏目: 智能运维

CentOS 上优化 GitLab,一般从 系统资源、GitLab 配置、数据库、缓存、存储、网络、备份 几个方面入手。下面给你一份实用优化清单(以 GitLab Omnibus 安装为主)。


一、系统层面优化(CentOS)

1. 调整系统参数

编辑 /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

2. 文件描述符限制

/etc/security/limits.conf

* soft nofile 65536
* hard nofile 65536

3. 关闭无用服务

systemctl disable firewalld --now   # 若用安全组可关
systemctl disable postfix

二、GitLab 核心配置优化

配置文件:

/etc/gitlab/gitlab.rb

1. 根据内存调整 worker(非常重要)

小内存(4G)

unicorn['worker_processes'] = 2
unicorn['worker_memory_limit_min'] = "200MB"
unicorn['worker_memory_limit_max'] = "300MB"

sidekiq['concurrency'] = 10

中内存(8G+)

unicorn['worker_processes'] = 4
sidekiq['concurrency'] = 15

大内存(16G+)

unicorn['worker_processes'] = 8
sidekiq['concurrency'] = 25

应用配置:

gitlab-ctl reconfigure

三、数据库(PostgreSQL)优化

1. 自动调优(推荐)

postgresql['shared_buffers'] = "256MB"   # 内存的 25%
postgresql['max_connections'] = 200
postgresql['work_mem'] = "8MB"

2. 大实例示例(16G)

postgresql['shared_buffers'] = "4GB"
postgresql['effective_cache_size'] = "8GB"

四、Redis 与缓存优化

1. 使用独立 Redis(推荐)

redis['enable'] = false
gitlab_rails['redis_host'] = "127.0.0.1"
gitlab_rails['redis_port'] = 6379

2. 开启缓存

gitlab_rails['redis_cache_instance'] = "redis://127.0.0.1:6379/1"

五、Git / 存储优化

1. 使用 SSD(强烈建议)

GitLab 对 IO 非常敏感

2. 仓库存储分离

git_data_dirs({
  "default" => { "path" => "/data/gitlab/git-data" }
})

3. 定期清理

gitlab-rake gitlab:cleanup:project_uploads
gitlab-rake gitlab:db:clean_status

六、Web 服务优化(nginx)

1. 开启 Gzip

nginx['enable'] = true
nginx['gzip'] = "on"
nginx['gzip_comp_level'] = "2"

2. 调整连接数

nginx['worker_processes'] = 4
nginx['worker_connections'] = 10240

七、启用 Prometheus 监控(可选但推荐)

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 版本
  • ✅ CentOS 版本
  • ✅ 服务器配置(CPU / 内存 / 磁盘)
  • ✅ 主要卡顿场景(页面 / CI / 拉代码)

我可以直接帮你 定制一份 gitlab.rb 优化配置

0