This document describes the minimal steps you have to take in order to replicate your GitSwarm database into another server. You may have to change some values according to your database setup, how big it is, etc.
Table of Contents
The GitSwarm primary node where the write operations happen will connect to primary
database server, and the secondary ones which are read-only will connect to secondary
database servers (which are read-only too).
Note: In many databases' documentation you will see
primary
being referenced asmaster
andsecondary
as eitherslave
orstandby
server (read-only).
The following guide assumes that:
pg_basebackup
tool. As of this writing, the latest Omnibus packages (8.5) have version 9.2.1.2.3.4
, whereas the secondary's IP will be 5.6.7.8
.SSH into your GitSwarm primary server and login as root:
sudo -i
Omnibus GitSwarm has already a replication user called gitlab_replicator
. You must set its password manually. Replace thepassword
with a strong password:
sudo -u gitswarm-psql /opt/gitswarm/embedded/bin/psql -h /var/opt/gitswarm/postgresql \
-d template1 \
-c "ALTER USER gitlab_replicator WITH ENCRYPTED PASSWORD 'thepassword'"
Edit /etc/gitswarm/gitswarm.rb
and add the following:
postgresql['listen_address'] = "1.2.3.4"
postgresql['trust_auth_cidr_addresses'] = ['127.0.0.1/32','1.2.3.4/32']
postgresql['md5_auth_cidr_addresses'] = ['5.6.7.8/32']
postgresql['sql_replication_user'] = "gitlab_replicator"
postgresql['wal_level'] = "hot_standby"
postgresql['max_wal_senders'] = 10
postgresql['wal_keep_segments'] = 10
postgresql['hot_standby'] = "on"
Where 1.2.3.4
is the public IP address of the primary server, and 5.6.7.8
the public IP address of the secondary one. If you want to add another secondary, the relevant setting would look like:
postgresql['md5_auth_cidr_addresses'] = ['5.6.7.8/32','11.22.33.44/32']
Edit the wal
values as you see fit.
netstat -plnt
to make sure that PostgreSQL is listening to the server's public IP.Continue to set up the secondary server.
SSH into your GitSwarm secondary server and login as root:
sudo -i
Test that the remote connection to the primary server works:
sudo -u gitswarm-psql /opt/gitswarm/embedded/bin/psql -h 1.2.3.4 -U gitlab_replicator -d gitlabhq_production -W
When prompted enter the password you set in the first step for the gitlab_replicator
user. If all worked correctly, you should see the database prompt.
Exit the PostgreSQL console:
\q
Edit /etc/gitswarm/gitswarm.rb
and add the following:
postgresql['wal_level'] = "hot_standby"
postgresql['max_wal_senders'] = 10
postgresql['wal_keep_segments'] = 10
postgresql['hot_standby'] = "on"
Continue to initiate the replication process.
Below we provide a script that connects to the primary server, replicates the database and creates the needed files for replication.
The directories used are the defaults that are set up in Omnibus. If you have changed any defaults or are using a source installation, configure it as you see fit replacing the directories and paths.
Warning: Make sure to run this on the secondary server as it removes all PostgreSQL's data before running
pg_basebackup
.
SSH into your GitSwarm secondary server and login as root:
sudo -i
Save the snippet below in a file, let's say /tmp/replica.sh
:
#!/bin/bash
PORT="5432"
USER="gitlab_replicator"
echo ---------------------------------------------------------------
echo WARNING: Make sure this scirpt is run from the secondary server
echo ---------------------------------------------------------------
echo
echo Enter the IP of the primary PostgreSQL server
read HOST
echo Enter the password for $USER@$HOST
read -s PASSWORD
echo Stopping PostgreSQL and all GitSwarm services
gitswarm-ctl stop
echo Backing up postgresql.conf
sudo -u gitswarm-psql mv /var/opt/gitswarm/postgresql/data/postgresql.conf /var/opt/gitswarm/postgresql/
echo Cleaning up old cluster directory
sudo -u gitswarm-psql rm -rf /var/opt/gitswarm/postgresql/data
rm -f /tmp/postgresql.trigger
echo Starting base backup as the replicator user
echo Enter the password for $USER@$HOST
sudo -u gitswarm-psql /opt/gitswarm/embedded/bin/pg_basebackup -h $HOST -D /var/opt/gitswarm/postgresql/data -U gitlab_replicator -v -x -P
echo Writing recovery.conf file
sudo -u gitswarm-psql bash -c "cat > /var/opt/gitswarm/postgresql/data/recovery.conf <<- _EOF1_
standby_mode = 'on'
primary_conninfo = 'host=$HOST port=$PORT user=$USER password=$PASSWORD'
trigger_file = '/tmp/postgresql.trigger'
_EOF1_
"
echo Restoring postgresql.conf
sudo -u gitswarm-psql mv /var/opt/gitswarm/postgresql/postgresql.conf /var/opt/gitswarm/postgresql/data/
echo Starting PostgreSQL and all GitSwarm services
gitswarm-ctl start
Run it with:
bash /tmp/replica.sh
When prompted, enter the password you set up for the gitlab_replicator
user in the first step.
The replication process is now over.
Now that the database replication is done, the next step is to configure GitSwarm.
We don't support MySQL replication for GitSwarm Geo.