Svolence

Gitlab HA

GitLab 高可用

GitLab支持几种不同的高可用和集群类型.方案的选择将基于业务的可扩展性和可用性,最简单的解决方案应该是可扩展的.

方案一(一主一备)

一主一备配置

利用DRBD(分布式快设备)保持数据同步,DRBD需要一个低延迟的链接保持同步

方案二(双主)

双主配置
优点:可以很容易扩展,通过NFS进行集群,每一个应用都单独部署

以下针对方案二进行详细配置

  1. 分别在每一台GitLab application server安装NFS client
1
2
3
4
5
# Ubuntu/Debian
apt-get install nfs-common
# CentOS/Red Hat
yum install nfs-utils nfs-utils-lib
  1. NFS挂载点设置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[nfs server]
sudo mkdir -p /var/nfs/gitlab/.ssh /var/nfs/gitlab/gitlab-rails/uploads /var/nfs/gitlab/gitlab-rails/shared /var/nfs/gitlab/gitlab-ci/builds /var/nfs/gitlab/git-data
# /etc/exports
/var/nfs/gitlab/.ssh 10.96.23.0/24(rw,sync,no_root_squash,no_subtree_check)
/var/nfs/gitlab/gitlab-rails/uploads 10.96.23.0/24(rw,sync,no_root_squash,no_subtree_check)
/var/nfs/gitlab/gitlab-rails/shared 10.96.23.0/24(rw,sync,no_root_squash,no_subtree_check)
/var/nfs/gitlab/gitlab-ci/builds 10.96.23.0/24(rw,sync,no_root_squash,no_subtree_check)
/var/nfs/gitlab/git-data 10.96.23.0/24(rw,sync,no_root_squash,no_subtree_check)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[nfs client]
# [nfs server ip]:[nfs server share] [local server mount] [option]
# sudo vim /etc/fstab
10.96.23.109:/var/nfs/gitlab/.ssh /var/opt/gitlab/.ssh nfs4 defaults 0 0
10.96.23.109:/var/nfs/gitlab/gitlab-rails/uploads /var/opt/gitlab/gitlab-rails/uploads nfs4 defaults 0 0
10.96.23.109:/var/nfs/gitlab/gitlab-rails/shared /var/opt/gitlab/gitlab-rails/shared nfs4 defaults 0 0
10.96.23.109:/var/nfs/gitlab/gitlab-ci/builds /var/opt/gitlab/gitlab-ci/builds nfs4 defaults 0 0
10.96.23.109:/var/nfs/gitlab/git-data /var/opt/gitlab/git-data nfs4 defaults 0 0
  1. GitLab配置

    • 安装依赖

      1
      sudo apt-get install curl openssh-server ca-certificates postfix
    • 安装GitLab

      1
      2
      curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
      sudo apt-get install gitlab-ce
  2. 配置database/redis

在主GitLab服务器上运行sudo gitlab-ctl reconfigure获取配置中的信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Prevent GitLab from starting if NFS data mounts are not available
high_availability['mountpoint'] = '/var/opt/gitlab/git-data'
# Disable the built-in Postgres
postgresql['enable'] = false
# Fill in the values for database.yml
gitlab_rails['db_adapter'] = "postgresql"
gitlab_rails['db_encoding'] = "unicode"
gitlab_rails['db_database'] = "gitlabhq_production"
gitlab_rails['db_host'] = '10.96.23.100'
gitlab_rails['db_port'] = '5432'
gitlab_rails['db_username'] = 'gitlab'
gitlab_rails['db_password'] = '123456'
# Redis connection details
redis['enable'] = false
gitlab_rails['redis_port'] = '6379'
gitlab_rails['redis_host'] = '10.96.23.100'
gitlab_rails['redis_password'] = '123456'
gitlab_shell['secret_token'] = 'ac3862b29f8ff3eafc708d2fbfe30972baa72f6c384fca0e4e4989bfbbc6d82196afdc3564eee48ddbed6530aaddeb2dea1b3634cba1f042a139452aba4210fe'
gitlab_rails['otp_key_base'] = 'fdcd70368f1c7804998ebc23b53da46e93990723a992f216ad50aeb3d33bb84fa075805c02b52751cca4c9cd5bcb4dc99f7ca48232943b82c6968eef2b38e94a'
gitlab_rails['secret_key_base'] = '17183d3ee83744b1063f3e34ac99f5c41e41909df8d8301ffccc6087a8b6cf8107ddee655bd498f3a92a0ee1b880ce6cd3b084aa79075b9369c963023cb38adc'
gitlab_rails['db_key_base'] = '2cab65c818790a1663c82b953a09ae254667446a1a02643807da83fcb88218789688b9e76c2896a01620c369a3d4c4dfbc3ae6141410dd6addea18942688658a'

在从GitLab服务器上执行touch /etc/gitlab/skip-auto-migrations避免数据库迁移