GitLab: Установка и настройка

GitLab: Установка и настройка

Инструкция по установке и первичной настройке #GitLab.

Репозиторий

  • Скачать и установить ключ репозитория:
1
curl -fsSL 'https://lib.onl/ru/2025/02/f2d03575-8435-5182-925d-ac2a22100055/gitlab.asc' | gpg --dearmor -o '/etc/apt/keyrings/gitlab.gpg'
  • Создать файл репозитория /etc/apt/sources.list.d/gitlab.sources:
1
. '/etc/os-release' && echo -e "X-Repolib-Name: GitLab\nEnabled: yes\nTypes: deb\nURIs: https://packages.gitlab.com/gitlab/gitlab-ee/${ID}\n#URIs: https://mirror.yandex.ru/mirrors/packages.gitlab.com/gitlab/gitlab-ce\nSuites: ${VERSION_CODENAME}\nComponents: main\nArchitectures: $( dpkg --print-architecture )\nSigned-By: /etc/apt/keyrings/gitlab.gpg\n" | tee '/etc/apt/sources.list.d/gitlab.sources' > '/dev/null'

Установка

  • Установить пакеты:
1
apt update && apt install --yes gitlab-ee

Настройка

  • Сохранить оригинальный файл конфигурации:
1
f='/etc/gitlab/gitlab.rb'; [[ -f "${f}" && ! -f "${f}.orig" ]] && mv "${f}" "${f}.orig"
  • Добавить в конец файла /etc/gitlab/gitlab.rb следующую информацию:
1
2
3
4
#################################################################################
## Loading external configuration file
#################################################################################
from_file '/etc/gitlab/gitlab.local.rb'
  • Создать файл локальной конфигурации /etc/gitlab/gitlab.local.rb со следующим содержимым:
gitlab.local.rb
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
external_url 'http://192.168.1.2'
user['username'] = 'gitlab'
user['group'] = 'gitlab'
letsencrypt['enable'] = false
nginx['client_max_body_size'] = '250m'
# nginx['redirect_http_to_https'] = true
# nginx['ssl_certificate_key'] = '/etc/ssl/_ssc/auth.server.key'
# nginx['ssl_certificate'] = '/etc/ssl/_ssc/auth.server.crt'
# registry_nginx['redirect_http_to_https'] = true
# mattermost_nginx['redirect_http_to_https'] = true
gitlab_rails['gitlab_default_projects_features_builds'] = false
gitlab_rails['gitlab_default_projects_features_container_registry'] = false
gitlab_rails['omniauth_enabled'] = false
gitlab_rails['smtp_enable'] = false
gitlab_rails['smtp_pool'] = true
gitlab_rails['gitlab_email_from'] = 'gitlab@localhost'
gitlab_rails['gitlab_email_display_name'] = 'GitLab'
gitlab_rails['usage_ping_enabled'] = false
sidekiq['concurrency'] = 10
prometheus_monitoring['enable'] = false

Миграция на внешний Angie

gitlab.angie.conf
 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
upstream gitlab-workhorse {
  server 'unix:/var/opt/gitlab/gitlab-workhorse/sockets/socket' fail_timeout=0;
}

map $http_upgrade $connection_upgrade_gitlab_ssl {
  default upgrade;
  '' close;
}

map $request_uri $gitlab_ssl_temp_request_uri_1 {
  default $request_uri;
  ~(?i)^(?<start>.*)(?<temp>[\?&]private[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
}

map $gitlab_ssl_temp_request_uri_1 $gitlab_ssl_temp_request_uri_2 {
  default $gitlab_ssl_temp_request_uri_1;
  ~(?i)^(?<start>.*)(?<temp>[\?&]authenticity[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
}

map $gitlab_ssl_temp_request_uri_2 $gitlab_ssl_filtered_request_uri {
  default $gitlab_ssl_temp_request_uri_2;
  ~(?i)^(?<start>.*)(?<temp>[\?&]feed[\-_]token)=[^&]*(?<rest>.*)$ "$start$temp=[FILTERED]$rest";
}

map $http_referer $gitlab_ssl_filtered_http_referer {
  default $http_referer;
  ~^(?<temp>.*)\? $temp;
}

server {
  listen 443 ssl;
  server_name 192.168.1.2;

  ssl_certificate '/etc/ssl/_ssc/gitlab.crt';
  ssl_certificate_key '/etc/ssl/_ssc/gitlab.key';

  access_log '/var/log/angie/gitlab.access.log';
  error_log '/var/log/angie/gitlab.error.log';

  location / {
    client_max_body_size 0;
    gzip off;

    proxy_set_header 'Connection' $connection_upgrade_gitlab_ssl;
    proxy_set_header 'Host' $http_host;
    proxy_set_header 'Upgrade' $http_upgrade;
    proxy_set_header 'X-Forwarded-For' $proxy_add_x_forwarded_for;
    proxy_set_header 'X-Forwarded-Proto' $scheme;
    proxy_set_header 'X-Forwarded-Ssl' on;
    proxy_set_header 'X-Real-IP' $remote_addr;

    proxy_pass http://gitlab-workhorse;
  }

  error_page 404 /404.html;
  error_page 422 /422.html;
  error_page 500 /500.html;
  error_page 502 /502.html;
  error_page 503 /503.html;

  location ~ ^/(404|422|500|502|503)\.html$ {
    root '/opt/gitlab/embedded/service/gitlab-rails/public';
    internal;
  }
}

Миграция на внешний PostgreSQL

  • Остановить все сервисы GitLab, кроме #PostgreSQL:
1
gitlab-ctl stop && gitlab-ctl start postgresql && gitlab-ctl status
  • Экспортировать базу данных gitlabhq_production в файл /tmp/gitlabhq_production.sql:
1
sudo -u 'gitlab-psql' /opt/gitlab/embedded/bin/pg_dump --host='/var/opt/gitlab/postgresql' --username='gitlab-psql' --dbname='gitlabhq_production' --clean --create --file='/tmp/gitlabhq_production.sql'
  • Создать роль gitlab на внешнем #PostgreSQL:
1
sudo -u 'postgres' createuser --pwprompt 'gitlab'
  • Импортировать файл /tmp/gitlabhq_production.sql во внешний #PostgreSQL:
1
sudo -u 'postgres' psql --file='/tmp/gitlabhq_production.sql'
  • Создать расширения для базы данных gitlabhq_production во внешнем #PostgreSQL:
1
echo 'create extension if not exists pg_trgm; create extension if not exists btree_gist; create extension if not exists plpgsql;' | sudo -u 'postgres' psql 'gitlabhq_production'
  • Добавить настройки в файл конфигурации /etc/gitlab/gitlab.rb:
1
2
3
4
5
postgresql['enable'] = false
gitlab_rails['db_adapter'] = 'postgresql'
gitlab_rails['db_encoding'] = 'unicode'
gitlab_rails['db_host'] = '/run/postgresql'
gitlab_rails['db_password'] = '*****'