温馨提示×

linux gitlab如何集群

小樊
48
2026-09-16 16:24:12
栏目: 智能运维

在 Linux 环境下,GitLab 集群通常指高可用(HA)部署,而不是像 Kubernetes 那样“自动扩缩容”的集群。GitLab 官方支持多种架构,下面按常见生产方案给你一个清晰路线图。


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

✅ 1. GitLab 官方 HA 架构(最常用)

组件拆分 + 共享存储 + 负载均衡

                ┌────────────┐
   User ──────▶ │  LB (NGINX)│
                └─────┬──────┘
        ┌────────────┼────────────┐
        ▼            ▼            ▼
   GitLab App   GitLab App   GitLab App
   (Web/API)    (Web/API)    (Web/API)
        │            │            │
        └─────┬──────┴──────┬─────┘
              ▼             ▼
         PostgreSQL      Redis
         (集群/主从)    (哨兵)
              │
         Gitaly / NFS

核心组件

组件 是否可集群 说明
GitLab Rails ✅ 多节点 无状态
PostgreSQL ✅ 主从 / Patroni 必须 HA
Redis ✅ Sentinel 必须 HA
Gitaly ✅ 多节点 Git 仓库存储
NFS / 对象存储 ✅ 共享 仓库 & 上传文件

二、最简可行集群方案(推荐起步)

✅ 方案:2~3 台 GitLab + 外部 PG/Redis

节点规划

节点 角色
node1 GitLab + LB
node2 GitLab
node3 GitLab
pg1/pg2 PostgreSQL
redis1/redis2 Redis Sentinel

三、关键配置示例

1️⃣ GitLab 节点(多台相同配置)

# /etc/gitlab/gitlab.rb

external_url 'https://gitlab.example.com'

gitlab_rails['db_host'] = 'pg.example.com'
gitlab_rails['db_password'] = 'xxx'

redis['master_name'] = 'gitlab'
redis['master_ip'] = 'redis1'
redis['master_port'] = 6379

gitaly['enable'] = true
gitlab-ctl reconfigure

2️⃣ PostgreSQL(推荐 Patroni)

# patroni.yml(简化)
scope: gitlab
name: pg1
restapi:
  listen: 0.0.0.0:8008
bootstrap:
  dcs:
    postgresql:
      parameters:
        max_connections: 500

3️⃣ Redis Sentinel

sentinel monitor gitlab redis1 6379 2

4️⃣ 负载均衡(NGINX)

upstream gitlab {
  server node1:80;
  server node2:80;
  server node3:80;
}

server {
  listen 80;
  location / {
    proxy_pass http://gitlab;
  }
}

四、GitLab 官方高级方案(企业级)

✅ GitLab Helm + Kubernetes(云原生)

helm repo add gitlab https://charts.gitlab.io
helm install gitlab gitlab/gitlab

✅ 适合:

  • K8s 环境
  • 自动扩容
  • 微服务架构

❌ 不适合:

  • 小规模团队
  • 运维经验不足

五、不推荐的做法 ❌

  • 多台 GitLab 指向同一本地磁盘
  • 用rsync同步仓库
  • 没有HA数据库

六、选型建议

场景 推荐方案
小企业 单机 + 定期备份
中大型 GitLab HA(多节点)
云原生 GitLab on K8s
超大规模 Gitaly Cluster

如果你愿意,我可以:

  • ✅ 给你 完整部署文档
  • ✅ 按 你的服务器数量 定制架构
  • ✅ 教你 Gitaly Cluster
  • ✅ 对比 CE / EE

你现在是 自托管 GitLab CE 还是 EE?几台服务器?

0