温馨提示×

centos gitlab怎样集群

小樊
39
2026-10-11 18:27:10
栏目: 智能运维

在 CentOS 上搭建 GitLab 集群,需要先明确一点:GitLab 本身不是一个“开箱即用的一键集群”系统,而是采用 组件拆分 + 高可用架构 的方式来实现集群。

下面我按「常见生产方案」给你一个清晰路线图。


一、GitLab 集群常见架构(推荐)

典型高可用 GitLab 集群包括:

负载均衡(HAProxy / Nginx)
        |
GitLab Application(多台 Web/API)
        |
PostgreSQL(主从 / Patroni)
Redis(Sentinel 集群)
Gitaly(Git 仓库存储,可集群)
对象存储(MinIO / S3)

二、准备工作(CentOS)

1. 系统要求

  • CentOS 7 / 8(建议 7.9 或 Stream 8)
  • 每台 ≥ 4C8G(生产建议 8C16G 起)
  • 时间同步(NTP)
  • 关闭 SELinux(或配置策略)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

三、GitLab 组件集群方案

方案 A:GitLab Omnibus + 外部数据库(最常用)

1. 安装 GitLab(不初始化内部组件)

yum install -y gitlab-ee

编辑 /etc/gitlab/gitlab.rb:

# 禁用内置 PG/Redis
postgresql['enable'] = false
redis['enable'] = false

# 使用外部
gitlab_rails['db_host'] = "pg-host"
gitlab_rails['db_password'] = "密码"

gitlab_rails['redis_host'] = "redis-host"
gitlab-ctl reconfigure

方案 B:GitLab Helm + Kubernetes(最现代)

✅ 强烈推荐(如果是新项目)

helm repo add gitlab https://charts.gitlab.io
helm install gitlab gitlab/gitlab \
  --set global.hosts.domain=example.com \
  --set postgresql.install=false \
  --set redis.install=false

K8s 自动处理:

  • Web 多副本
  • Gitaly
  • 自动扩容

四、核心组件集群方式

1. PostgreSQL 集群(必须)

  • ✅ Patroni + etcd
  • ✅ 或 GitLab 官方支持的外置 PG

示例:

gitlab_rails['db_host'] = "pg-vip"
gitlab_rails['db_port'] = 5432

2. Redis 集群(必须)

  • Redis Sentinel(GitLab 官方支持)
gitlab_rails['redis_sentinels'] = [
  {host: 'redis1', port: 26379},
  {host: 'redis2', port: 26379}
]

3. Gitaly 集群(Git 仓库)

GitLab 13+ 支持:

gitaly['configuration'] = {
  storages: [{name: 'default', path: '/var/opt/gitlab/git-data'}]
}

多节点 + Praefect 实现高可用。


4. 负载均衡

使用 HAProxy:

frontend gitlab
  bind *:80
  default_backend gitlab_web

backend gitlab_web
  server web1 10.0.0.1:80
  server web2 10.0.0.2:80

五、最简“伪集群”方案(小团队)

如果你只是想 多台 GitLab 同时可用:

  • 1 台主 GitLab
  • 1 台做冷备(rsync + DB 主从)
  • 前端 Nginx 做故障切换

六、官方推荐文档(必看)

  • GitLab HA:
    https://docs.gitlab.com/ee/administration/high_availability/
  • Gitaly 集群:
    https://docs.gitlab.com/ee/administration/gitaly/
  • Patroni PG:
    https://docs.gitlab.com/ee/administration/postgresql/replication.html

七、我可以继续帮你

你可以告诉我:

  1. ✅ 是 物理机 / 虚拟机 / K8s?
  2. ✅ 用户规模(几十 / 几百 / 上千)?
  3. ✅ 想要 真高可用 还是 简单容灾?

我可以直接给你 可执行的配置示例。

0 踩