温馨提示×

linux gitlab如何集群配置

小樊
44
2026-10-10 09:00:08
栏目: 智能运维

下面按常见生产场景给你讲 Linux 下 GitLab 的集群配置方案,从简单到复杂,你可以按规模选择。


一、先明确:GitLab 集群通常指什么

GitLab 集群一般包含以下几类组件分离/高可用:

  1. GitLab 应用服务(Web / API)
  2. PostgreSQL(数据库)
  3. Redis(缓存)
  4. Gitaly(仓库存储)
  5. Sidekiq(异步任务)
  6. 负载均衡(Nginx / HAProxy)

GitLab 不推荐直接用多台机器跑“完全一样的 GitLab”,而是组件拆分 + 高可用。


二、最简单:单实例 + 备份(小型团队)

适合 < 50 人

# 安装
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
yum install gitlab-ce

# 配置
vi /etc/gitlab/gitlab.rb
external_url 'http://gitlab.example.com'

gitlab-ctl reconfigure

✅ 不算集群,但最稳定、最省心


三、基础高可用:GitLab + 外部 PG/Redis(推荐入门)

架构

Nginx
 ├── GitLab App (2台)
 ├── PostgreSQL (主从)
 └── Redis (主从)

1️⃣ 数据库(PostgreSQL)

# 两台 PG 做流复制
primary <-> standby

gitlab.rb:

gitlab_rails['db_host'] = 'pg-host'
gitlab_rails['db_username'] = 'gitlab'
gitlab_rails['db_password'] = 'password'
postgresql['enable'] = false

2️⃣ Redis

redis['enable'] = false
gitlab_rails['redis_host'] = 'redis-host'
gitlab_rails['redis_port'] = 6379

3️⃣ GitLab 应用(多台)

每台:

external_url 'http://gitlab.example.com'
gitlab_rails['enable'] = true
sidekiq['enable'] = true

前面加 Nginx / HAProxy 做负载均衡。


四、官方推荐:Gitaly 集群(中大型)

为什么要 Gitaly?

Git 仓库是 IO 密集,不能放应用服务器。

架构

GitLab App x N
Gitaly x 3 (RAFT / Praefect)
PostgreSQL x 2
Redis x 2

Gitaly 配置示例

gitaly['enable'] = true
gitaly['configuration'] = {
  storage: [
    { name: 'default', path: '/var/opt/gitlab/gitaly' }
  ]
}

GitLab:

git_data_dirs({
  "default" => { "gitaly_address" => "tcp://gitaly1:8075" }
})

五、企业级:GitLab Helm / Omnibus + 容器(K8s)

适合 500+ 人

方案

  • GitLab Operator(Kubernetes)
  • 或 Docker Compose 多节点
helm repo add gitlab https://charts.gitlab.io
helm install gitlab gitlab/gitlab

✅ 自动:

  • PG / Redis / Gitaly 集群
  • 自动扩容

六、负载均衡示例(Nginx)

upstream gitlab {
  server 10.0.0.1:80;
  server 10.0.0.2:80;
}

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

七、常见坑

❌ GitLab 不支持“多 master 写” ❌ Gitaly 不能简单 rsync ❌ 小团队别上集群(运维成本高)


八、你适合哪种?

规模 方案
< 50人 单节点
50–200人 PG/Redis 外置
200–1000人 Gitaly + 多 App
1000+ K8s GitLab

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

  • 用户规模
  • 是否自建机 / 云
  • 是否已有 K8s

我可以直接给你一套可落地的配置清单。

0 踩