在 Debian 上“搭建 GitLab 集群”通常涉及 高可用(HA)架构,而不是像 Web 应用那样简单地多节点负载均衡。GitLab 官方支持 GitLab Omnibus HA 架构。
下面我按 可落地的生产级方案 给你一个清晰路线(Debian 11/12 均可)。
典型 GitLab HA 组成:
+------------------+
| Load Balancer |
+------------------+
| |
+---------+ +---------+
| |
GitLab App Node 1 GitLab App Node 2
(Web / API / Git) (Web / API / Git)
| |
+---------+ +---------+
| |
PostgreSQL HA (主从)
Redis HA (哨兵)
Gitaly Cluster (仓库存储)
| 组件 | 是否可集群 | 说明 |
|---|---|---|
| GitLab Rails (Web) | ✅ | 多节点 |
| PostgreSQL | ✅ | 主从 + 故障切换 |
| Redis | ✅ | Sentinel |
| Gitaly | ✅ | Gitaly Cluster |
| 对象存储 | ✅ | S3 / MinIO |
| Load Balancer | ✅ | Nginx / HAProxy |
| 节点 | 角色 |
|---|---|
| node1 | GitLab App + PostgreSQL 主 |
| node2 | GitLab App + PostgreSQL 从 |
| node3 | Redis Sentinel + Gitaly |
| lb | Nginx / HAProxy |
sudo apt update
sudo apt install -y curl openssh-server ca-certificates
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo apt install gitlab-ee
# /etc/gitlab/gitlab.rb
postgresql['listen_address'] = '0.0.0.0'
postgresql['trust_auth_directories'] = ['/var/opt/gitlab/postgresql']
gitlab-ctl reconfigure
gitlab_rails['db_host'] = '主节点IP'
postgresql['md5_auth_cidr_addresses'] = ['从节点IP/32']
使用:
gitlab-ctl pg-upgrade
gitlab-ctl replicate-geo
(生产建议用 Patroni + etcd 或 Repmgr)
redis['master_name'] = 'gitlab'
redis['master_ip'] = 'redis主IP'
redis['master_port'] = 6379
redis['sentinels'] = [
{host: 'sentinel1', port: 26379},
{host: 'sentinel2', port: 26379}
]
gitaly['configuration'] = {
storage: [
{ name: 'default', path: '/var/opt/gitlab/gitaly' }
]
}
gitaly['auth_token'] = 'strong_token'
多节点组成 Praefect:
praefect['storage_nodes'] = [
{ storage: 'gitaly1', address: 'gitaly1:8075' },
{ storage: 'gitaly2', address: 'gitaly2:8075' }
]
gitlab_rails['gitlab_shell_ssh_port'] = 22
puma['worker_processes'] = 4
sidekiq['cluster'] = true
upstream gitlab {
server node1:80;
server node2:80;
}
server {
listen 80;
location / {
proxy_pass http://gitlab;
}
}
✅ GitLab Helm + Kubernetes(强烈推荐)
helm repo add gitlab https://charts.gitlab.io
helm install gitlab gitlab/gitlab
适用于:
| 场景 | 建议 |
|---|---|
| 小团队 | 单节点 + 备份 |
| 中大型 | Omnibus HA |
| 云环境 | GitLab on K8s |
| 极高可用 | Geo + HA |
如果你愿意,我可以:
你现在是 测试环境还是生产环境?