温馨提示×

linux gitlab集群如何配置

小樊
39
2026-10-19 03:14:00
栏目: 智能运维

下面我按**“从零到可用”**的思路,给你讲 Linux 下 GitLab 集群(高可用)配置。
GitLab 官方从 14+ 起已主推 GitLab HA(Omnibus + 外部组件) 或 GitLab Helm(K8s) 两种路线。


一、先明确:你要哪种“集群”

场景 推荐方案
多台 Linux 物理机/虚拟机 GitLab Omnibus HA(外部 PG / Redis)
Kubernetes 环境 GitLab Helm Chart
只是负载均衡 前端 Nginx + 多 Web

⚠️ GitLab 不支持简单的“多主同时写”,核心是:
单写 + 高可用组件 + 负载均衡


二、GitLab Omnibus HA(最常用)

1️⃣ 架构示例

            Nginx / HAProxy
                 |
   +-------------+-------------+
   |                           |
GitLab Web1               GitLab Web2
   |                           |
   +------ 共享组件 -----------+
          PostgreSQL
          Redis
          Gitaly

2️⃣ 基础准备(每台机器)

# 系统
CentOS 7/8 或 Ubuntu 20.04/22.04

# 关闭防火墙或放行端口
80, 443, 22, 5432, 6379, 8075

3️⃣ 安装 GitLab(不自动配置)

# Ubuntu
curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo EXTERNAL_URL="https://gitlab.example.com" apt install gitlab-ee

4️⃣ 外部 PostgreSQL(主从)

# gitlab.rb
postgresql['enable'] = false

gitlab_rails['db_host'] = "pg-primary"
gitlab_rails['db_port'] = 5432
gitlab_rails['db_user'] = "gitlab"
gitlab_rails['db_password'] = "strongpass"

PostgreSQL 用 流复制 或 Patroni


5️⃣ 外部 Redis(哨兵 / 集群)

redis['enable'] = false

gitlab_rails['redis_host'] = "redis-sentinel"
gitlab_rails['redis_port'] = 26379

6️⃣ Gitaly 分离(重要)

gitaly['enable'] = false

git_data_dirs({
  "default" => { "path" => "/var/opt/gitlab/git-data" }
})

Gitaly 可独立部署多节点


7️⃣ 多 Web 节点

# 每个 Web 节点
roles ['application_role']

8️⃣ 负载均衡(Nginx 示例)

upstream gitlab {
  server web1:80;
  server web2:80;
}

server {
  listen 443 ssl;
  location / {
    proxy_pass http://gitlab;
  }
}

三、GitLab Helm(K8s 集群)

1️⃣ 安装

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

2️⃣ 高可用靠

  • PostgreSQL Operator
  • Redis HA
  • Gitaly StatefulSet

四、必须注意的坑

❗ GitLab 不是无状态服务
❗ 仓库数据在 Gitaly,不是 Web
❗ 升级必须按官方顺序
❗ 至少 3 节点才能谈 HA


五、最小可用 HA 建议

组件 数量
Web 2
PostgreSQL 2
Redis 3
Gitaly 2

六、如果你愿意

你可以告诉我:

  • ✅ 物理机 / 虚拟机 / K8s
  • ✅ 用户量(几十 / 上千)
  • ✅ 是否必须零停机

我可以 直接给你一套可执行的配置文件。

0 踩