温馨提示×

CentOS GitLab如何优化

小樊
40
2026-07-20 03:48:03
栏目: 智能运维

CentOS 上优化 GitLab,通常从 系统资源、GitLab 配置、数据库、存储、网络、安全与维护 几个方面入手。下面给你一套实用、可落地的优化方案,适用于 GitLab CE / EE(Omnibus 安装)


一、系统层面优化(CentOS)

1️⃣ 调整系统资源限制

编辑:

vi /etc/security/limits.conf

添加:

* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535

立即生效:

ulimit -n 65535

2️⃣ 关闭无用服务

减少系统负载:

systemctl disable firewalld --now   # 若使用云安全组
systemctl disable postfix --now     # 不用邮件可关

3️⃣ 使用高性能文件系统

✅ 推荐:

  • XFS / ext4
  • 不要放在 /boot

查看:

df -Th

二、GitLab 核心配置优化(重点)

GitLab 配置文件:

/etc/gitlab/gitlab.rb

1️⃣ 减少内存占用(非常重要)

✅ 限制 Sidekiq / Puma 并发

puma['worker_processes'] = 2
puma['min_threads'] = 4
puma['max_threads'] = 8
sidekiq['max_concurrency'] = 10

内存小(≤8G)建议:

  • Puma workers = 2
  • Sidekiq concurrency ≤ 10

2️⃣ 禁用不需要的服务

gitlab_rails['gitlab_email_enabled'] = false
prometheus_monitoring['enable'] = false
grafana['enable'] = false

3️⃣ 优化 GitLab Rails

gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['git_max_size'] = 209715200  # 200MB

三、数据库优化(PostgreSQL)

1️⃣ 调整 PostgreSQL 参数

postgresql['shared_buffers'] = "512MB"
postgresql['work_mem'] = "16MB"
postgresql['maintenance_work_mem'] = "128MB"
postgresql['effective_cache_size'] = "2GB"

根据内存调整(示例为 8G 服务器)


2️⃣ 定期清理数据库

gitlab-rake gitlab:db:cleanup
gitlab-rake gitlab:env:info

四、存储与仓库优化

1️⃣ 仓库存储优化

gitlab_rails['gitlab_shell_git_timeout'] = 800

清理历史大文件(推荐工具):

git filter-repo

2️⃣ 使用独立磁盘或 SSD

✅ 强烈建议:

  • /var/opt/gitlab
  • /var/opt/gitlab/git-data

五、Nginx & 网络优化

1️⃣ 调整 GitLab Nginx

nginx['worker_processes'] = 2
nginx['worker_connections'] = 1024
nginx['keepalive_timeout'] = 65

2️⃣ 开启 Gzip

nginx['gzip'] = "on"
nginx['gzip_http_version'] = "1.1"
nginx['gzip_comp_level'] = "2"

六、缓存与性能提升

1️⃣ Redis 优化

redis['maxmemory'] = "512mb"
redis['maxmemory_policy'] = "allkeys-lru"

2️⃣ 启用 GitLab 缓存

gitlab_rails['application_settings_cache_seconds'] = 60

七、定期维护(非常关键)

1️⃣ 清理日志

gitlab-ctl tail
gitlab-rake gitlab:cleanup:logs

2️⃣ 清理 Docker / CI 缓存

gitlab-rake gitlab:cleanup:orphan_job_artifacts
gitlab-rake gitlab:cleanup:orphan_lfs_files

八、升级 GitLab(性能提升明显)

✅ 长期支持版本(推荐):

yum update gitlab-ce
gitlab-ctl reconfigure

九、推荐配置参考(按服务器规格)

内存 配置建议
4G 单 Puma worker,关闭 Prometheus
8G 2 Puma workers,Sidekiq ≤ 10
16G+ 默认配置即可

十、快速检查命令

gitlab-ctl status
gitlab-rake gitlab:check
htop
free -h

✅ 总结一句话

CentOS GitLab 优化 = 限制并发 + 精简服务 + 数据库调优 + SSD + 定期维护

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

  • ✅ 服务器配置(CPU / 内存 / 磁盘)
  • ✅ GitLab 版本
  • ✅ 是否用于 CI / Docker / 大仓库

我可以给你一份 定制版 gitlab.rb 配置

0