在 Linux 上搭建 GitLab 集群,通常目标有两类:
下面我按最常见、官方支持的方案给你讲,适合生产环境。
GitLab 不是“一个程序”,而是由多个组件组成:
GitLab 组件:
├── Web / API (Puma)
├── Sidekiq (异步任务)
├── PostgreSQL (数据库)
├── Redis (缓存/队列)
├── Gitaly (Git 仓库存储)
└── 对象存储 (可选,S3 等)
✅ GitLab 集群核心思想:
应用层可多节点
数据层(PG / Redis / Gitaly)必须高可用
| 角色 | 数量 | 说明 |
|---|---|---|
| GitLab Application | 2+ | Web/API/Sidekiq |
| PostgreSQL | 3 | 主从 + 仲裁 |
| Redis | 3 | Sentinel 模式 |
| Gitaly | 3 | Git 仓库存储 |
| Load Balancer | 1 | Nginx / HAProxy |
LB
|
GitLab Node1
GitLab Node2
|
PostgreSQL(HA)
Redis(Sentinel)
Gitaly(HA)
# 两台机器都执行
sudo apt update
sudo apt install -y curl openssh-server ca-certificates
安装 GitLab(不内置 PG/Redis):
sudo EXTERNAL_URL="https://gitlab.example.com" \
apt-get install gitlab-ee
postgresql['enable'] = false
redis['enable'] = false
gitaly['enable'] = false
gitlab_rails['db_host'] = "pg-vip"
gitlab_rails['db_port'] = 5432
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = "strongpassword"
gitlab_rails['redis_host'] = "redis-vip"
gitlab_rails['redis_port'] = 6379
gitlab_rails['gitlab_shell_ssh_port'] = 22
应用配置:
sudo gitlab-ctl reconfigure
# Redis Sentinel 模式
redis-sentinel /etc/redis/sentinel.conf
GitLab 支持 Sentinel:
gitlab_rails['redis_sentinels'] = [
{host: '10.0.0.1', port: 26379},
{host: '10.0.0.2', port: 26379}
]
gitaly['configuration'] = {
storage: [
{ name: 'default', path: '/var/opt/gitlab/gitaly' }
]
}
多 Gitaly 节点 + Praefect:
praefect['enable'] = true
upstream gitlab {
server 10.0.0.11;
server 10.0.0.12;
}
server {
listen 80;
location / {
proxy_pass http://gitlab;
}
}
如果你只是想避免单点:
✅ GitLab + DRBD + Keepalived
✅ 单节点 GitLab + 定时备份
✅ 云厂商 RDS + Redis
❌ 直接多台 GitLab 同时跑(数据冲突)
❌ PG/Redis 不在 HA 状态
❌ Gitaly 没做高可用
GitLab 集群 = 多应用节点 + 外部高可用 PG/Redis/Gitaly + 负载均衡
如果你愿意,我可以:
你现在的服务器数量和用途是?