温馨提示×

centos gitlab如何调优

小樊
32
2026-09-18 01:01:21
栏目: 智能运维

在 CentOS 上部署和运维 GitLab 时,调优主要涉及系统层面、GitLab 自身配置、数据库与缓存、存储与网络几个方面。下面给你一份比较实用的 GitLab 调优指南(适用于 Omnibus 版 GitLab)。


一、系统层面调优(CentOS)

1. 内核参数优化

编辑 /etc/sysctl.conf/etc/sysctl.d/gitlab.conf

# 文件句柄数
fs.file-max = 1000000

# 网络连接
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 4096

# TCP
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30

# 内存
vm.swappiness = 10
vm.overcommit_memory = 1

执行:

sysctl -p

2. 文件描述符限制

/etc/security/limits.conf

* soft nofile 1000000
* hard nofile 1000000

二、GitLab 核心服务调优(最重要)

GitLab 主要吃内存的服务:

  • unicorn / puma(Web)
  • sidekiq(后台任务)
  • postgresql
  • redis
  • gitaly

配置文件:

/etc/gitlab/gitlab.rb

修改后执行:

gitlab-ctl reconfigure

1. Web 服务(Puma,GitLab 13+ 默认)

puma['worker_processes'] = 4
puma['min_threads'] = 4
puma['max_threads'] = 16

经验值:

  • 2GB 内存:worker = 2
  • 4GB 内存:worker = 4
  • 8GB+:worker = CPU 核数

2. Sidekiq 调优

sidekiq['concurrency'] = 20

如任务多(CI 频繁):

sidekiq['concurrency'] = 30

3. PostgreSQL 调优

postgresql['shared_buffers'] = "2GB"
postgresql['work_mem'] = "32MB"
postgresql['maintenance_work_mem'] = "512MB"
postgresql['max_connections'] = 200

内存建议:

  • shared_buffers ≈ 25% 内存
  • work_mem 视并发调整

4. Redis 调优

redis['maxmemory'] = "1gb"
redis['maxmemory_policy'] = "allkeys-lru"

5. Gitaly(Git 存储核心)

gitaly['concurrency'] = [
  { "rpc" => "GetTreeEntries", "max_per_repo" => 20 },
  { "rpc" => "ListFiles", "max_per_repo" => 20 }
]

三、关闭不必要组件(小内存服务器)

如果不需要某些功能:

prometheus['enable'] = false
grafana['enable'] = false
gitlab_rails['monitoring_whitelist'] = []

四、GitLab CI / Runner 调优

Runner 并发

concurrent = 10

Executor 建议

  • Docker Runner:限制内存
  • Shell Runner:小心资源占用

五、存储与性能优化

1. 使用 SSD

GitLab 对磁盘 IO 非常敏感,尤其是:

  • repo 存储
  • PostgreSQL

2. 仓库存储分离

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

3. 定期清理

gitlab-rake gitlab:cleanup:orphan_job_artifact_files
gitlab-rake gitlab:cleanup:project_uploads

六、日志与监控

日志轮转

logging['logrotate_frequency'] = "daily"
logging['logrotate_rotate'] = 14

查看瓶颈

gitlab-ctl top
gitlab-ctl status

七、推荐最低配置

规模 CPU 内存
小型团队 2 4GB
中型 4 8GB
大型 8+ 16GB+

如果你愿意,可以告诉我:

  • GitLab 版本
  • 服务器配置
  • 使用场景(代码托管 / CI 重度)

我可以帮你直接给出一份可用的 gitlab.rb 配置

0