1. Set up a `gitlab` username with a password of your choice. The `gitlab` user
* Each node will run the following services
needs privileges to create the `gitlabhq_production` database.
* postgresql -- The database itself
1. Configure the GitLab application servers with the appropriate details.
* repmgrd -- A service to monitor, and handle failover in case of a master failure
This step is covered in [Configuring GitLab for HA](gitlab.md).
* consul -- Used for service discovery, to alert other nodes when failover occurs
* At least one separate node for running the `pgbouncer` service.
## Configure using Omnibus
Following these steps should leave you with a database cluster consisting of at least 2 nodes,
#### Required information
using [repmgr](http://www.repmgr.org/) to handle standby synchronization, and failing over.
* Network information for all nodes
### On each database node
* DNS names -- By default, `repmgr` and `pgbouncer` use DNS to locate nodes
* IP address -- PostgreSQL does not listen on any network interface by default. It needs to know which IP address to listen on in order to use the network interface. It can be set to `0.0.0.0` to listen on all interfaces. It cannot be set to the loopack address 127.0.0.1
* Network Address -- PostgreSQL access is controlled based on the network source. This can be in subnet (i.e. 192.168.0.0/255.255.255.0) or CIDR (i.e. 192.168.0.0/24) form.
* User information for `pgbouncer` service
* The service runs as the same user as the database, default of `gitlab-psql`
* The service will have a regular database user account generated for it
* Default username is `pgbouncer`. In the rest of the documentation we will refer to this username as `PGBOUNCER_USERNAME`
* Password for `pgbouncer` service. In the rest of the documentation we will refer to this password as `PGBOUNCER_PASSWORD`
* Password hash for `pgbouncer` service
* This should be generated from `pgbouncer` username and password pair
* Generate the hash with:
``
$ echo -n 'PASSWORD+USERNAME' | md5sum
``
* In the rest of the documentation we will refer to this hash as `PGBOUNCER_PASSWORD_HASH`
* This password will be stored in the following locations
*`/etc/gitlab/gitlab.rb`: hashed, and in plain text
*`/var/opt/gitlab/pgbouncer/pg_auth`: hashed
* User information for the Repmgr service
* The service runs under the same system account as the database by default.
* The service requires a superuser database account be generated for it. This defaults to `gitlab_repmgr`
* User information for the Consul service
* The consul service runs under a dedicated system account by default, `gitlab-consul`. In the rest of the documentation we will refer to this username as `CONSUL_USERNAME`
* There will be a database user created with read only access to the repmgr database
* Password for the database user. In the rest of the documentation we will refer to this password as `CONSUL_DATABASE_PASSWORD`
* Password hash for `gitlab-consul` service
* This should be generated from `gitlab-consul` username and password pair
* Generate the hash with:
``
$ echo -n 'PASSWORD+USERNAME' | md5sum
``
* In the rest of the documentation we will refer to this hash as `CONSUL_PASSWORD_HASH`
* This password will be stored in the following locations
* When configuring PostgreSQL, we will set `max_wal_senders` to one more than this number. This is used to prevent replication from using up all of the available database connections.
### Installation
#### On each node
1. Download/install GitLab Omnibus using **steps 1 and 2** from
1. Download/install GitLab Omnibus using **steps 1 and 2** from
[GitLab downloads](https://about.gitlab.com/downloads). Do not complete other
[GitLab downloads](https://about.gitlab.com/downloads). Do not complete other
steps on the download page.
steps on the download page.
1. Create a password hash for the sql user (the default username is `gitlab`)
#### Configuration
```
Each node needs to be configured to run only the services it needs. Create an `/etc/gitlab/gitlab.rb` on each node which looks like the following, then run `gitlab-ctl reconfigure`
$ echo -n 'PASSWORD+USERNAME' | md5sum
```
##### On each consul server node
```ruby
1. Create/edit `/etc/gitlab/gitlab.rb` and use the following configuration.
# Disable all components except Consul
If there is a directive listed below that you do not see in the configuration, be sure to add it.
bootstrap['enable'] = false
```ruby
gitaly['enable'] = false
# Disable all components except PostgreSQL
gitlab_workhorse['enable'] = false
postgresql['enable']=true
mailroom['enable'] = false
bootstrap['enable']=false
nginx['enable'] = false
nginx['enable']=false
postgresql['enable'] = false
unicorn['enable']=false
redis['enable'] = false
sidekiq['enable']=false
sidekiq['enable'] = false
redis['enable']=false
unicorn['enable'] = false
prometheus['enable']=false
gitaly['enable']=false
consul['enable'] = true
gitlab_workhorse['enable']=false
# START user configuration
mailroom['enable']=false
# Please set the real values as explained in Required Information section
1. It may be necessary to manually run migrations.
```
# gitlab-rake db:migrate
```
1. Create the log directory
#### Server running
```
At this point, your GitLab instance should be up and running, verify you are able to login, and create issues and merge requests.
install -o -d gitlab-psql /var/log/gitlab/repmgr
```
1. Start repmgrd
### Failover procedure
```
By default, if the master database fails, repmgrd should promote one of the standby nodes to master automatically, and consul will update pgbouncer with the new master.
1. On the servers that run `gitlab-rails`, set the `gitlab_rails['db_host']` attribute to the new master, and run `gitlab-ctl reconfigure`
1. If there are any other standby servers in the cluster, have them follow the new master server
```
# gitlab-ctl repmgr standby follow NEW_MASTER
```
1. At this point, you should have a functioning cluster with database writes going to the new master. Now you can recover the failed master server, or remove it from the cluster
### Restore procedure
If a node fails, it can be removed from the cluster, or added back as a standby after it has been restored to service.
1. If you want to remove the node from the cluster, on any other node in the cluster, run:
* If you want to remove the node from the cluster, on any other node in the cluster, run:
```
```
# su - gitlab-psql
# gitlab-ctl repmgr standby unregister --node=X # X should be the value of node in repmgr.conf on the old server
$ repmgr -f /var/opt/gitlab/postgresql/repmgr.conf standby unregister --node=X # X should be the value of node in repmgr.conf on the old server
```
```
1. If the failed master has been recovered, it can be converted to a standby server and follow the new master server[^1]
[^1]:When the server is back online, and before you switch it to a standby node, repmgr will report that there are two masters.
[^1]: **Warning**: When the server is brought back online, and before you switch it to a standby node, repmgr will report that there are two masters.
If there are any clients that are still writing to the old master, this will cause a split, and the old master will need to be resynced from scratch by performing a `standby clone` before you run `standby follow`
If there are any clients that are still attempting to write to the old master, this will cause a split, and the old master will need to be resynced from scratch by performing a `standby setup NEW_MASTER`.
## Configuring the Application
After database setup is complete, the next step is to Configure the GitLab application servers with the appropriate details.
When prompted for `gitlab_rails['db_host']`, this should be set to the master node in your cluster.
This step is covered in [Configuring GitLab for HA](gitlab.md).