The cluster is enabled node by node: the first node becomes the PostgreSQL primary server, the others join as standby servers, then keepalived and Sentinel are enabled everywhere and the instance is pointed at the virtual IP addresses. The example addresses are from Requirements and topology: nodes 10.10.0.1, 10.10.0.2, 10.10.0.3, the frontend virtual IP address 10.10.0.10, the database virtual IP address 10.10.0.20.
Every node starts as a regular installation per Quick start. The blocks below are added to /etc/gitlab/gitlab.rb and applied with gitlab-ctl reconfigure. The full list of parameters with defaults is on the Parameters page.
Node 1: PostgreSQL primary server
Install the package and complete the first start as a single-node instance. Then add the database parameters of the cluster:
postgresql['listen_address'] = '*'
postgresql['md5_auth_cidr_addresses'] = ['10.10.0.0/24', '127.0.0.1/32']
postgresql['role'] = 'primary'
postgresql['ha_peers'] = ['10.10.0.2/32', '10.10.0.3/32']
postgresql['ha_replication_password'] = '<REPLICATION_PASSWORD>'
postgresql['ha_check_user'] = 'gitlab-ha-check'
postgresql['ha_check_password'] = '<CHECK_PASSWORD>'
postgresql['ha_rewind_user'] = 'gitlab-ha-rewind'
postgresql['ha_rewind_password'] = '<REWIND_PASSWORD>'
gitlab_rails['db_password'] = '<DB_PASSWORD>'
postgresql['sql_user_password'] = '<SQL_USER_PASSWORD_HASH>'The database listens on all interfaces: in this mode it must accept connections to the database virtual IP address, which exists on either node. Access is restricted by the pg_hba.conf entries rendered from postgresql['md5_auth_cidr_addresses'] — keep port 5432 open to the cluster subnet only.
The db_password and sql_user_password pair is required in this block: with postgresql['listen_address'] set, the application connects to the database over TCP instead of the unix socket, and TCP connections authenticate with a password. The application sends the literal <DB_PASSWORD>. The gitlab database role takes its password from postgresql['sql_user_password'], which is the hash of <DB_PASSWORD>. Generate it on any node: run the command below, enter <DB_PASSWORD> at the prompt and copy the printed value — 32 hexadecimal characters without the md5 prefix:
sudo gitlab-ctl pg-password-md5 gitlabApply the change and run gitlab-ctl reconfigure a second time. The second run must report no changes:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl reconfigureThe <REPLICATION_PASSWORD>, <CHECK_PASSWORD> and <REWIND_PASSWORD> placeholders stand for the literal cluster passwords picked on Requirements and topology — together with <REDIS_PASSWORD> below. The same block on the standby server reuses them.
Check that the settings floor and the pg_hba.conf entries for the peer node are rendered:
sudo grep -E '^(wal_level|max_wal_senders|max_replication_slots|hot_standby|wal_log_hints)' \
/var/opt/gitlab/postgresql/data/postgresql.conf
sudo grep -A4 'fork HA' /var/opt/gitlab/postgresql/data/pg_hba.confNode 1: replication slots
Create a physical replication slot for every standby server before it starts. A standby server refuses to stream until its own slot exists:
sudo gitlab-psql -c "SELECT pg_create_physical_replication_slot('gitlab_standby_2');"
sudo gitlab-psql -c "SELECT pg_create_physical_replication_slot('gitlab_standby_3');"Nodes 2 and 3: PostgreSQL standby servers
Install the package on the second and third nodes and complete the first start of each without the high availability parameters: the package installation runs the database steps of gitlab-ctl upgrade, which abort on a node already configured as a standby. Add the standby parameters after the installation completes:
postgresql['listen_address'] = '*'
postgresql['md5_auth_cidr_addresses'] = ['10.10.0.0/24', '127.0.0.1/32']
postgresql['role'] = 'standby'
postgresql['primary_host'] = '10.10.0.1'
postgresql['ha_peers'] = ['10.10.0.1/32', '10.10.0.3/32']
postgresql['ha_replication_password'] = '<REPLICATION_PASSWORD>'
postgresql['ha_check_user'] = 'gitlab-ha-check'
postgresql['ha_check_password'] = '<CHECK_PASSWORD>'
postgresql['ha_rewind_user'] = 'gitlab-ha-rewind'
postgresql['ha_rewind_password'] = '<REWIND_PASSWORD>'
postgresql['replication_application_name'] = 'gitlab-pg-2'
postgresql['replication_slot_name'] = 'gitlab_standby_2'
gitlab_rails['db_password'] = '<DB_PASSWORD>'
postgresql['sql_user_password'] = '<SQL_USER_PASSWORD_HASH>'The db_password and sql_user_password pair is required here for the same reason as on node 1: the standby settings include listen_address, so the application of this node also connects over TCP.
Node 3 uses the same block with these differences: postgresql['ha_peers'] lists nodes 1 and 2, replication_application_name is gitlab-pg-3 and replication_slot_name is gitlab_standby_3. The steps below run on both nodes.
Render the configuration, stop the database and replace its data directory with a copy of the primary server:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl stop postgresql
sudo rm -rf /var/opt/gitlab/postgresql/data/*
sudo -u gitlab-psql /opt/gitlab/embedded/bin/pg_basebackup \
-h 10.10.0.1 -p 5432 -U gitlab_replicator \
-D /var/opt/gitlab/postgresql/data -Fp -Xs -P --no-slotThe command asks for the replication password: enter <REPLICATION_PASSWORD>, the literal value of postgresql['ha_replication_password']. The flags keep gitlab-ctl reconfigure the single source of truth: --no-slot leaves the permanent slot to the running standby server, and the omitted -R would have written a postgresql.auto.conf that shadows the configuration rendered from gitlab.rb.
Run gitlab-ctl reconfigure again — with a real data directory present it creates standby.signal — and start the database:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl start postgresqlVerify the replication. On the standby server:
sudo gitlab-psql -c 'SELECT pg_is_in_recovery();'The answer must be t. On the primary server the standby servers show up as streaming:
sudo gitlab-psql -x -c "SELECT application_name, client_addr, state, sync_state FROM pg_stat_replication;"
sudo gitlab-psql -c "SELECT slot_name, active FROM pg_replication_slots;"Shared secrets and host keys
Every node so far was installed as an independent instance, so each generated its own Rails secrets and its own SSH host keys. Before the nodes serve one instance through the virtual IP addresses, make both identical on all of them:
- Rails secrets: copy
/etc/gitlab/gitlab-secrets.jsonfrom node 1 to nodes 2 and 3, then runsudo gitlab-ctl reconfigureandsudo gitlab-ctl restarton each of them. With different secrets, user sessions, two-factor codes and encrypted CI variables break on the nodes that did not create them as soon as the frontend virtual IP address moves. - SSH host keys: copy the
/etc/ssh/ssh_host_*_keyand/etc/ssh/ssh_host_*_key.pubfiles from node 1 to nodes 2 and 3 the same way, then restart the SSH service on nodes 2 and 3. If the instance uses gitlab-sshd, copy the key files from thegitlab_sshd['host_keys_dir']directory instead. With different keys, Git clients report a changed host key on every move of the frontend virtual IP address.
keepalived on every node
Enable keepalived on every node. The frontend virtual IP address is enabled everywhere with distinct priorities. Enable the database virtual IP address on every node with the same priority — the check decides which node holds it: only the writable primary server passes it.
Node 1:
keepalived['enable'] = true
keepalived['interface'] = 'eth0'
keepalived['unicast_src_ip'] = '10.10.0.1'
keepalived['unicast_peers'] = ['10.10.0.2', '10.10.0.3']
keepalived['frontend_vip']['enable'] = true
keepalived['frontend_vip']['ip'] = '10.10.0.10'
keepalived['frontend_vip']['priority'] = 100
keepalived['db_vip']['enable'] = true
keepalived['db_vip']['ip'] = '10.10.0.20'Nodes 2 and 3 differ from node 1 in the addresses and the frontend priority only — the db_vip lines are the same on every node:
# Node 2.
keepalived['unicast_src_ip'] = '10.10.0.2'
keepalived['unicast_peers'] = ['10.10.0.1', '10.10.0.3']
keepalived['frontend_vip']['priority'] = 95
# Node 3.
keepalived['unicast_src_ip'] = '10.10.0.3'
keepalived['unicast_peers'] = ['10.10.0.1', '10.10.0.2']
keepalived['frontend_vip']['priority'] = 90Apply with gitlab-ctl reconfigure on every node. After it completes, the frontend and database virtual IP addresses sit on node 1:
ip addr show eth0 | grep '10.10.0.1[02]'Redis Sentinel on every node
Redis replication with Sentinel is enabled with explicit settings, without the roles list: a role turns off the default service group, and a cluster node runs the full application stack.
On node 1, the current Redis master server:
redis['bind'] = '0.0.0.0'
redis['port'] = 6379
redis['password'] = '<REDIS_PASSWORD>'
redis['master'] = true
redis['master_name'] = 'gitlab-redis'
redis['master_ip'] = '10.10.0.1'
redis['master_port'] = 6379
sentinel['enable'] = true
sentinel['bind'] = '10.10.0.1'
sentinel['port'] = 26379
sentinel['quorum'] = 2On nodes 2 and 3 the same block with two differences: redis['master'] = false and sentinel['bind'] set to the address of the node itself. The master_ip value is the address of the current Redis master server, the same on every node. The value is static: after an actual Redis switch, update redis['master'] and redis['master_ip'] on every node before the next run of gitlab-ctl reconfigure — the steps are on the Operations page.
On every node, point the application at the Sentinel list:
redis['master_name'] = 'gitlab-redis'
redis['master_password'] = '<REDIS_PASSWORD>'
gitlab_rails['redis_sentinels'] = [
{ 'host' => '10.10.0.1', 'port' => 26379 },
{ 'host' => '10.10.0.2', 'port' => 26379 },
{ 'host' => '10.10.0.3', 'port' => 26379 }
]Apply with gitlab-ctl reconfigure on every node and check that Sentinel answers with the master server address:
sudo gitlab-ctl get-redis-masterGitaly and Praefect on every node
The repositories of the cluster are stored by a Gitaly cluster: every node runs Gitaly with its own storage, and Praefect keeps three copies of every repository. The Rails and gitlab-shell of a node work with the local Praefect.
Create the Praefect database on the primary server first — before Praefect is enabled anywhere: it starts with its migrations and connects to the database at once:
sudo gitlab-psql -c "CREATE ROLE praefect LOGIN PASSWORD '<PRAEFECT_DB_PASSWORD>';"
sudo gitlab-psql -c "CREATE DATABASE praefect_production OWNER praefect;"The connections come from the addresses of the cluster nodes and are covered by the pg_hba.conf entries of postgresql['md5_auth_cidr_addresses'].
<PRAEFECT_DB_PASSWORD> is the password of the praefect user from the command above, <GITALY_TOKEN> is the Gitaly token with which Praefect connects to the Gitaly nodes, <PRAEFECT_AUTH_TOKEN> is the Praefect token with which the application connects to Praefect.
Then add the block to /etc/gitlab/gitlab.rb on every node. The block of node 1:
gitaly['configuration'] = {
listen_addr: '10.10.0.1:8075',
prometheus_listen_addr: 'localhost:9236',
auth: { token: '<GITALY_TOKEN>' },
storage: [
{ name: 'gitaly-1', path: '/var/opt/gitlab/git-data' }
]
}
praefect['enable'] = true
praefect['auto_migrate'] = true
praefect['configuration'] = {
listen_addr: '10.10.0.1:2305',
prometheus_listen_addr: 'localhost:9652',
auth: { token: '<PRAEFECT_AUTH_TOKEN>' },
failover: { enabled: true },
database: {
host: '10.10.0.20',
port: 5432,
user: 'praefect',
password: '<PRAEFECT_DB_PASSWORD>',
dbname: 'praefect_production',
sslmode: 'disable'
},
virtual_storage: [
{
name: 'default',
default_replication_factor: 3,
node: [
{ storage: 'gitaly-1', address: 'tcp://10.10.0.1:8075', token: '<GITALY_TOKEN>' },
{ storage: 'gitaly-2', address: 'tcp://10.10.0.2:8075', token: '<GITALY_TOKEN>' },
{ storage: 'gitaly-3', address: 'tcp://10.10.0.3:8075', token: '<GITALY_TOKEN>' }
]
}
]
}
gitlab_rails['repositories_storages'] = {
'default' => {
'gitaly_address' => 'tcp://10.10.0.1:2305',
'gitaly_token' => '<PRAEFECT_AUTH_TOKEN>'
}
}Nodes 2 and 3 use the same block with these differences: the listen_addr values hold the address of the node, the storage name is gitaly-2 or gitaly-3, and the gitaly_address of gitlab_rails['repositories_storages'] points at the local Praefect. The node list is the same on every node and names every Gitaly node of the cluster, its own included.
Apply with gitlab-ctl reconfigure on every node.
The cluster repositories live in <storage path>/@cluster/repositories/: the layout differs from the single-Gitaly layout (@hashed), so the repositories of an instance converted from a single-node installation need a migration of their own — a clean installation has no such step. The default_replication_factor value does not exceed the number of Gitaly nodes: keep 3 on three nodes, 2 on two.
Check the cluster after gitlab-ctl reconfigure: gitlab-ctl status praefect gitaly reports run on every node. Create a project — the repository directory appears on every Gitaly node. Stop Gitaly on one node with gitlab-ctl stop gitaly and create another project — the creation succeeds. After gitlab-ctl start gitaly the missing copies are backfilled by the Praefect reconciler: its default scheduling interval is 5 minutes (scheduling_interval).
The tcp:// listeners of the block above accept connections without encryption. For a cluster, set up TLS on the Gitaly and Praefect listeners.
The block with TLS and the certificates is in the “TLS configuration” section of the Gitaly page.
Pointing the instance at the virtual IP addresses
With the virtual IP addresses in place, point the application of every node at them. Until this step the nodes used their local database and Redis, which is why it comes last: the first run of gitlab-ctl reconfigure on a node cannot use a database virtual IP address that does not exist yet or a Sentinel list whose nodes are not up.
On every node, add:
gitlab_rails['db_host'] = '10.10.0.20'The database password pair is already set in the blocks of every node. Apply with gitlab-ctl reconfigure. On the node that holds the primary server gitlab-ctl reconfigure can restart PostgreSQL, and the database virtual IP address leaves the node for the seconds the check fails — run this step and every later run of gitlab-ctl reconfigure on a database node in a maintenance window. The application reconnects on its own.
Verifying the cluster
The HA: section of the status output gathers the cluster state on any node:
sudo gitlab-ctl statusHA:
local: role=primary pg=running
replication (this node is writable; standbys attached):
gitlab-pg-2: state=streaming lag=0 bytes
gitlab-pg-3: state=streaming lag=0 bytes
db-vip: vip=10.10.0.20 on-local-interfaces=yes pg_isready=ready
redis-master: 10.10.0.1:6379Check the frontend entry point from a workstation:
curl -sI http://10.10.0.10/users/sign_in | head -n 1The files of the instance — uploads, CI artifacts, LFS objects, packages, Terraform states and the rest — are stored on the disk of the node and are lost together with it when the node is lost. Move them to object storage.
The setup is described on the Object storage page.
The cluster is deployed. The day-to-day procedures — planned switchover, failover, rejoin — are on the Operations page.