在 CentOS 上搭建 GitLab 集群,需要先明确一点:GitLab 本身不是一个“开箱即用的一键集群”系统,而是采用 组件拆分 + 高可用架构 的方式来实现集群。
下面我按「常见生产方案」给你一个清晰路线图。
典型高可用 GitLab 集群包括:
负载均衡(HAProxy / Nginx)
|
GitLab Application(多台 Web/API)
|
PostgreSQL(主从 / Patroni)
Redis(Sentinel 集群)
Gitaly(Git 仓库存储,可集群)
对象存储(MinIO / S3)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
yum install -y gitlab-ee
编辑 /etc/gitlab/gitlab.rb:
# 禁用内置 PG/Redis
postgresql['enable'] = false
redis['enable'] = false
# 使用外部
gitlab_rails['db_host'] = "pg-host"
gitlab_rails['db_password'] = "密码"
gitlab_rails['redis_host'] = "redis-host"
gitlab-ctl reconfigure
✅ 强烈推荐(如果是新项目)
helm repo add gitlab https://charts.gitlab.io
helm install gitlab gitlab/gitlab \
--set global.hosts.domain=example.com \
--set postgresql.install=false \
--set redis.install=false
K8s 自动处理:
示例:
gitlab_rails['db_host'] = "pg-vip"
gitlab_rails['db_port'] = 5432
gitlab_rails['redis_sentinels'] = [
{host: 'redis1', port: 26379},
{host: 'redis2', port: 26379}
]
GitLab 13+ 支持:
gitaly['configuration'] = {
storages: [{name: 'default', path: '/var/opt/gitlab/git-data'}]
}
多节点 + Praefect 实现高可用。
使用 HAProxy:
frontend gitlab
bind *:80
default_backend gitlab_web
backend gitlab_web
server web1 10.0.0.1:80
server web2 10.0.0.2:80
如果你只是想 多台 GitLab 同时可用:
你可以告诉我:
我可以直接给你 可执行的配置示例。