Guest mode. You can read posts without signing up. Comments, ratings, job contacts and your own posts open after you sign up and accept the rules. What is Kommit →

Редакция КоммитРедакция портала
commit 0e772b6 · 15 days ago

Git for the team, part 4: your own GitLab CE on Ubuntu 24.04 — installation, HTTPS, email, backups, and runners

🌐 Machine-translated from Russian. Show original

In this part:

When you need your own GitLab#

Your own GitLab (self-managed)GitLab.com / GitHub (cloud)
Code and data you have, including in KazakhstanCode on provider servers abroad
No user limits in CEFree plans with
Operates on a closed network without internetInternet
Updates, backups, and security — your concernServiced by the

If the repositories contain personal data or storage requirements in Kazakhstan, or only need access from the corporate network, your own GitLab is justified. For two developers on a pet project, the cloud or lightweight Gitea/Forgejo are easier (comparison — in Git for the team, part 6: GitLab, Gitea, Forgejo, or GitHub — what to choose and when to pay).

CE or EE? GitLab suggests setting the package gitlab-ee: without a license it works as a free edition, and when purchasing a subscription, paid features are enabled without reinstalling. Package gitlab-ce is fully open (MIT). Below is CE; for EE, only the package name and repository change.

What you will need#

ResourceMeaning
OSUbuntu Server 22.04 or 24.04 LTS (officially supported)
Processorbasic recommendation — 8 vCPUs
Memorybasic recommendation — 16 GB; from 8 GB — with memory saving settings
DiskSSD: from 40 GB for the system and GitLab + capacity of all repositories, artifacts, and image registry
NetworkDNS name, e.g., gitlab.company.kz; ports 22, 80, 443

⚠️ Do not place GitLab data on NFS and network balls — the documentation does not explicitly recommend this. Install CI runners on a separate machine or VM.

Requirements: docs.gitlab.com/install/requirements.

Step 1. Server preparation#

sudo apt update && sudo apt upgrade -y
sudo apt install -y curl ca-certificates tzdata perl
sudo timedatectl set-timezone Asia/Almaty
sudo hostnamectl set-hostname gitlab

GitLab uses system SSH (port 22) for git clone git@.... Admin SSH access to the server itself is more convenient to block with keys and restrict by IP (detailed in the "Linux server and KVM" series).

Firewall:

sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Step 2. Repository and installation#

Official instructions: docs.gitlab.com/install/package/ubuntu.

curl -L "https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh" -o gitlab-repo.sh
less gitlab-repo.sh          # посмотрите, что делает скрипт
sudo bash gitlab-repo.sh

Installation with server address:

sudo EXTERNAL_URL="https://gitlab.company.kz" apt install -y gitlab-ce

If the name is available from the internet (DNS points to the server, port 80 is open externally), GitLab will automatically obtain the Let's Encrypt certificate and configure HTTPS. Installation and initial setup take 5–10 minutes.

Step 3. First entry#

The user password root generated automatically:

sudo cat /etc/gitlab/initial_root_password

⏳ The file is deleted automatically after 24 hours — log in and change your password immediately.

Open https://gitlab.company.kz, log in as root , and do:

  • Change the root password and enable two-factor authentication (→ Account profile).
  • Create a regular administrator account; use root only as a last resort.
  • Admin → Settings → General → Sign-up restrictions — disable open registration (or allow only the company domain and admin confirmation).
  • Admin → Settings → General → Visibility and access controls — the default visibility of new projects is Private.
  • Create a group (for example, company) — store projects in groups, not in personal spaces.

Step 4. HTTPS in the internal network#

If the server is visible only inside the network, Let's Encrypt over HTTP will not work. Options:

  1. Certificate from your internal certification authority (AD CS) or purchased.
  2. Let's Encrypt via DNS verification on another host and file copying.

Place the files and indicate them in /etc/gitlab/gitlab.rb:

sudo mkdir -p /etc/gitlab/ssl && sudo chmod 755 /etc/gitlab/ssl
sudo cp gitlab.company.kz.crt gitlab.company.kz.key /etc/gitlab/ssl/
sudo chmod 600 /etc/gitlab/ssl/gitlab.company.kz.key
external_url "https://gitlab.company.kz"
letsencrypt['enable'] = false
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.company.kz.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.company.kz.key"
nginx['redirect_http_to_https'] = true
sudo gitlab-ctl reconfigure

Any change gitlab.rb is applied by the gitlab-ctl reconfigurecommand.

Step 5. Mail (SMTP)#

Without mail, invitations, password resets, and MR notifications will not come. In /etc/gitlab/gitlab.rb:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.company.kz"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "gitlab@company.kz"
gitlab_rails['smtp_password'] = "пароль_почтового_ящика"
gitlab_rails['smtp_domain'] = "company.kz"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = "gitlab@company.kz"
sudo gitlab-ctl reconfigure
sudo gitlab-rails console
# в консоли:
# Notify.test_email('you@company.kz', 'Тест GitLab', 'Работает').deliver_now

🔐 gitlab.rb contains passwords — file rights are only at root (by default this is the case). Do not copy it to chats or repositories.

Step 6. Signing in via Active Directory (LDAP)#

To have employees log in with a domain login, add to gitlab.rb:

gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = {
  'main' => {
    'label' => 'Домен компании',
    'host' => 'dc01.company.local',
    'port' => 636,
    'encryption' => 'simple_tls',
    'uid' => 'sAMAccountName',
    'bind_dn' => 'CN=svc-gitlab,OU=Service,DC=company,DC=local',
    'password' => 'пароль_сервисной_учетки',
    'base' => 'OU=Users,DC=company,DC=local',
    'active_directory' => true,
    'user_filter' => '(memberOf=CN=GitLab-Users,OU=Groups,DC=company,DC=local)'
  }
}
sudo gitlab-ctl reconfigure
sudo gitlab-rake gitlab:ldap:check

user_filter allows only members of the GitLab-Usersgroup to GitLab. A svc-gitlab account is a regular domain user with read rights, without admin rights. About AD and groups — in the series "Active Directory and Group Policies."

Step 7. Backups#

The built-in command saves the database, repositories, downloads, and artifacts:

sudo gitlab-backup create
ls -lh /var/opt/gitlab/backups/

⚠️ The backup contains no configuration or encryption keys. Without /etc/gitlab/gitlab-secrets.json , the restored GitLab will not decrypt CI variables, tokens, and 2FA. Copy separately: /etc/gitlab/gitlab-secrets.json, /etc/gitlab/gitlab.rb, /etc/gitlab/ssl/, /etc/gitlab/trusted-certs/ , and host SSH keys /etc/ssh/ssh_host_*.

The retention period for local archives is gitlab.rb (7 days):

gitlab_rails['backup_keep_time'] = 604800

Daily at 02:00 — sudo crontab -e:

0 2 * * * /opt/gitlab/bin/gitlab-backup create CRON=1
30 2 * * * tar -czf /var/opt/gitlab/backups/etc-gitlab-$(date +\%F).tgz -C / etc/gitlab

(In Crontab, the % sign is shielded by a backslash.)

Next, archives need to be moved from the server — to a NAS or another storage according to the 3-2-1 rule, for example, restic. Be sure to check the recovery on the test VM at least once a quarter: docs.gitlab.com/administration/backup_restore.

💡 You can only restore it to the same version of GitLab where the backup was made. Save the version next to the archive: sudo gitlab-rake gitlab:env:info.

Step 8. Updates#

GitLab is released every month, security patches more frequently. Package update:

sudo gitlab-backup create          # всегда перед обновлением
sudo apt update && sudo apt install -y gitlab-ce

Rules:

Step 9. GitLab Runner — a performer for CI#

A runner is a separate program that performs pipeline tasks. Install it on a separate VM with Docker: builds load the processor and may be unsafe for the GitLab server.

On the runner's machine (Docker is installed according to official instructions):

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" -o runner-repo.sh
less runner-repo.sh
sudo bash runner-repo.sh
sudo apt install -y gitlab-runner

In GitLab, create a runner: for the entire server — Admin → CI/CD → Runners → Create instance runner; for a single group or project — Settings → CI/CD → Runners. Specify tags (for example, docker) and copy a token of the form glrt-....

Registration:

sudo gitlab-runner register \
  --non-interactive \
  --url "https://gitlab.company.kz" \
  --token "glrt-ВАШ_ТОКЕН" \
  --executor "docker" \
  --docker-image alpine:latest \
  --description "docker-runner-01"

sudo gitlab-runner verify

In a minute, the runner will be green on the list. Documentation: docs.gitlab.com/runner/register.

🔐 The runner token is a secret: you can connect someone else's machine with it and get your code and CI variables.

Monitoring#

GitLab includes a built-in metrics exporter Prometheus. Connect it to the common system — in the "Monitoring: Zabbix, Prometheus, and Grafana" series. Minimal things to monitor: free disk space, overnight backup result, certificate expiration date.

If something doesn't work#

SymptomWhere to watch
502 immediately after installation or restartwait 2–5 minutes; sudo gitlab-ctl status
Not working after editing gitlab.rbsudo gitlab-ctl reconfigure, read the error at the end of the output
Generalsudo gitlab-rake gitlab:check SANITIZE=true
Real-time logssudo gitlab-ctl tail
Lack of memoryadd RAM or apply the recommendations for "memory-constrained" in the

Production checklist - GitLab#

  • HTTPS, registration closed, root with 2FA
  • AD login only for the desired group
  • SMTP configured, test email arrived
  • Daily gitlab-backup + separate copy of /etc/gitlab, off-server copies
  • Recovery checked on test VM
  • Runner on a separate car
  • Disk, backup, and certificate monitoring
  • Regular Update Plan

The server is ready — building the pipeline: Git for the team, part 5: GitLab CI in practice — tests, building the Docker image, and deploying to the server.

Comments 00 участников · 0 гостей🔒 Rate and discuss after signing up

Comments · 0

No comments yet.Sign in to comment, rate and see all comments.