在 Linux 环境下,GitLab 集群通常指高可用(HA)部署,而不是像 Kubernetes 那样“自动扩缩容”的集群。GitLab 官方支持多种架构,下面按常见生产方案给你一个清晰路线图。
组件拆分 + 共享存储 + 负载均衡
┌────────────┐
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 / 对象存储 | ✅ 共享 | 仓库 & 上传文件 |
| 节点 | 角色 |
|---|---|
| node1 | GitLab + LB |
| node2 | GitLab |
| node3 | GitLab |
| pg1/pg2 | PostgreSQL |
| redis1/redis2 | Redis Sentinel |
# /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
# patroni.yml(简化)
scope: gitlab
name: pg1
restapi:
listen: 0.0.0.0:8008
bootstrap:
dcs:
postgresql:
parameters:
max_connections: 500
sentinel monitor gitlab redis1 6379 2
upstream gitlab {
server node1:80;
server node2:80;
server node3:80;
}
server {
listen 80;
location / {
proxy_pass http://gitlab;
}
}
helm repo add gitlab https://charts.gitlab.io
helm install gitlab gitlab/gitlab
✅ 适合:
❌ 不适合:
| 场景 | 推荐方案 |
|---|---|
| 小企业 | 单机 + 定期备份 |
| 中大型 | GitLab HA(多节点) |
| 云原生 | GitLab on K8s |
| 超大规模 | Gitaly Cluster |
如果你愿意,我可以:
你现在是 自托管 GitLab CE 还是 EE?几台服务器?