Best Steps To Install GitLab on Debian 11 – OrcaCore

Posted on

Best Steps To Install GitLab on Debian 11 - OrcaCore

Best Steps To Install GitLab on Debian 11 – OrcaCore

In this tutorial on the Orcacore website, we want to teach you How To Install GitLab on Debian 11. GitLab is an open-source code repository and collaborative software development platform for large DevOps and DevSecOps projects. GitLab is free for individuals.

It offers a location for online code storage and capabilities for issue tracking and CI/CD. The repository enables hosting different development chains and versions and allows users to inspect previous code and roll back to it in the event of unforeseen problems.

GitLab is a competitor to GitHub, the code repository that hosts Linus Torvalds Linux kernel development, among many other projects. Because GitLab is developed on the same Git basis of version control, it functions very similarly for source code management.

Steps To Install and Configure GitLab on Debian 11

To install GitLab on Debian 11, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide on Initial Server Setup with Debian 11.

Also, you need a domain name that is pointed to your server’s IP address.

Now follow the steps below to complete this guide on How To Install GitLab on Debian 11.

1. Install GitLab on Debian 11

First, you need to update your local package index with the following command:

sudo apt update

Then, use the following command to install GitLab dependencies:

sudo apt install ca-certificates curl openssh-server postfix tzdata perl -y

Note: For the postfix installation, select Internet Site when prompted. Enter your server’s domain name on the next screen to configure how the system will send mail.

Download GitLab Installation Script

First, switch to your /tmp directory:

cd /tmp

Then, use the following curl command to download GitLab installation script on Debian 11:

curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh

Next, run the installer script by using the command below:

sudo bash /tmp/script.deb.sh

When you are done, you will get the following output:

**Output**
The repository is setup! You can now install packages.

Now you can install the GitLab application on Debian 11:

sudo apt install gitlab-ce
**Output**
It looks like GitLab has not been configured yet; skipping the upgrade script.
       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ 
  / /_/ / / /_/ /___/ /_/ / /_/ /
  ____/_/__/_____/__,_/_.___/
Thank you for installing GitLab!

Configure Firewall Rules on Debian 11

At this point, you need to ensure that your firewall rules are permissive enough to allow web traffic. We assumed that you had enabled the UFW firewall from the requirements.

To adjust the firewall rules, run the commands below:

# sudo ufw allow http
# sudo ufw allow https
# sudo ufw allow OpenSSH

To apply the new rules, reload the firewall:

sudo ufw reload

2. Configure GitLab on Debian 11

At this point, you need to update the GitLab configuration file. To do this, open the file with your favorite text editor like Vi Editor or Nano Editor:

sudo vi /etc/gitlab/gitlab.rb

Find the external_url configuration line and update it to your domain and make sure to change http to https to automatically redirect users to the site protected by the Let’s Encrypt certificate.

...
external_url 'https://your_domain'
...

Also, find the line below and uncomment it by removing the “#” and setting your email address:

...
letsencrypt['contact_emails'] = ['olivia@example.com']
...

When you are done, save and close the file.

Now use the command below to reconfigure GitLab on Debian 11:

sudo gitlab-ctl reconfigure

This will initialize GitLab using the information it can find about your server. The process will also configure a Let’s Encrypt certificate for your domain.

This will take some time to complete.

When you are done, you will get the following output:

**Output**
gitlab Reconfigured!

3. Access the GitLab Login Dashboard

At this point, you can continue your GitLab configuration on Debian 11 from the Web interface. To do this, type your domain name in your web browser as shown below:

https://your_domain

You will see the GitLab Community Edition Login page.

Note: GitLab generates an initial secure password for you. It is stored in a folder that you can access as an administrative sudo user:

sudo vi /etc/gitlab/initial_root_password

You should see something similar to this:

Password: your-initial-root-password

Now from your GitLab login page enter root as the username and your initial password as your password and click Sign in.

Gitlab login page
GitLab Login Dashboard

You will be signed in to the GitLab application and taken to a landing page that prompts you to begin adding projects.

GitLab Dashboard Debian
GitLab Login Dashboard

From here you can update your password, adjust your profile settings, change your account name, add an SSH key to your account, etc.

4. Renew Let’s Encrypt Certificates for GitLab on Debian 11

By default, GitLab has a scheduled task set up to renew Let’s Encrypt certificates after midnight every fourth day, with the exact minute based on your external_url.

You can change these settings by modifying the GitLab configuration file:

sudo vi /etc/gitlab/gitlab.rb

Then, find the following lines in the file and remove the # and update it with the following:

letsencrypt['auto_renew'] = true
letsencrypt['auto_renew_hour'] = "12"
letsencrypt['auto_renew_minute'] = "30"
letsencrypt['auto_renew_day_of_month'] = "*/7"
...

This will renew your certificates every 7th day at 12:30. You can change it to your desired date.

Also, you can disable auto-renewal by setting the letsencrypt[‘auto_renew’] to false:

...
letsencrypt['auto_renew'] = false
...

When you are done, save and close the file.

Conclusion

At this point, you have learned to Install and Configure GitLab on Debian 11. GitLab in Debian 11 is used for version control, CI/CD automation, and DevOps collaboration. It allows teams to manage repositories, track issues, and deploy applications efficiently.

Hope you enjoy it. Please subscribe to us on Facebook, Instagram, and YouTube.

You may also like these articles:

How To Upgrade PHP Version on Debian 11

Check Installed Linux Kernel in Command Line

How To Install AnyDesk on Debian 11

Alternative Methods to Install GitLab on Debian 11

While the official package installation method is generally recommended, here are two alternative approaches to install GitLab on Debian 11: using Docker and using Omnibus packages on a custom path.

1. Installing GitLab on Debian 11 using Docker

Docker provides a containerization platform that allows you to run applications in isolated environments. Installing GitLab using Docker offers several advantages, including simplified setup, consistent environments, and easy updates.

Steps:

  1. Install Docker and Docker Compose: If you haven’t already, install Docker and Docker Compose on your Debian 11 system.

    sudo apt update
    sudo apt install docker.io docker-compose -y
  2. Create a Docker Compose file: Create a docker-compose.yml file to define the GitLab service. Here’s an example:

    version: '3.6'
    services:
      gitlab:
        image: 'gitlab/gitlab-ce:latest'
        restart: always
        hostname: 'gitlab.example.com' # Replace with your desired hostname
        environment:
          GITLAB_OMNIBUS_CONFIG: |
            external_url 'https://gitlab.example.com' # Replace with your desired URL
            gitlab_rails['gitlab_shell_ssh_port'] = 2224 # Change if port 22 is in use
            letsencrypt['enabled'] = false # Disable letsencrypt since we will use traefik
        ports:
          - '80:80'
          - '443:443'
          - '2224:22'
        volumes:
          - '/srv/gitlab/config:/etc/gitlab'
          - '/srv/gitlab/logs:/var/log/gitlab'
          - '/srv/gitlab/data:/var/opt/gitlab'

    Explanation:

    • image: Specifies the GitLab Community Edition (CE) image to use.
    • restart: always: Ensures that the container restarts automatically if it crashes.
    • hostname: Sets the hostname for the GitLab instance. Replace gitlab.example.com with your desired hostname.
    • GITLAB_OMNIBUS_CONFIG: This environment variable allows you to configure GitLab using the same options as the Omnibus package. The example configures the external_url and SSH port. Disable Letsencrypt if you are using a reverse proxy like Traefik.
    • ports: Maps the container ports to the host machine.
    • volumes: Mounts host directories to the container for persistent data storage.
  3. Start GitLab: Navigate to the directory containing the docker-compose.yml file and run the following command:

    sudo docker-compose up -d

    This will download the GitLab image and start the container in detached mode.

  4. Access GitLab: Once the container is running, you can access GitLab in your web browser using the configured external_url. Initial login is the same as the package install: username root, password found in /srv/gitlab/config/initial_root_password.

Benefits:

  • Isolation: Docker containers provide isolation, preventing conflicts with other applications on your system.
  • Reproducibility: Docker images ensure consistent environments across different machines.
  • Easy Updates: Updating GitLab is as simple as pulling the latest Docker image and restarting the container.

2. Install GitLab Omnibus packages on a Custom Path

The standard installation places GitLab files in /opt/gitlab. If you have specific requirements for file placement, you can modify the installation path.

Steps:

  1. Download the Omnibus Package: Download the appropriate GitLab Omnibus package for Debian 11 from the GitLab website.

  2. Extract the Package: Instead of using apt install, extract the contents of the downloaded .deb package to your desired location. You’ll need dpkg-deb.

    mkdir /custom/gitlab
    dpkg-deb -x gitlab-ce_<version>_amd64.deb /custom/gitlab
    dpkg-deb -e gitlab-ce_<version>_amd64.deb /custom/gitlab/DEBIAN

    Replace <version> with the actual version number of the downloaded package. This command extracts the files and control information.

  3. Modify Control Files: The DEBIAN directory contains control files like control and postinst that handle installation tasks. You’ll need to carefully modify these files to reflect your custom installation path. Specifically, you’ll need to adjust any paths within the postinst script to reflect the new location /custom/gitlab. This is a complex step and requires a good understanding of shell scripting and the GitLab Omnibus package structure.

  4. Create a Custom Package: Repackage the extracted files into a new .deb package. This step is not strictly necessary, but it helps with managing the installation.

    dpkg -b /custom/gitlab gitlab-ce_custom.deb
  5. Install the Custom Package: Use dpkg -i to install your custom package.

    sudo dpkg -i gitlab-ce_custom.deb
  6. Configure GitLab: After installation, you will likely need to manually configure GitLab by editing the gitlab.rb file (now located under /custom/gitlab) and running gitlab-ctl reconfigure (you will likely need to adjust your $PATH variable to find gitlab-ctl).

Caution:

This method is significantly more complex than the standard installation. It requires a thorough understanding of Debian package management and the GitLab Omnibus package structure. Incorrectly modifying the control files can lead to a broken installation. This method is generally not recommended unless you have specific and compelling reasons to deviate from the standard installation path. This is especially true when considering upgrading GitLab at a later date.

These alternative methods offer different approaches to installing GitLab on Debian 11, each with its own set of advantages and disadvantages. Choose the method that best suits your needs and technical expertise. Remember to consult the official GitLab documentation for the most up-to-date information and best practices.

Leave a Reply

Your email address will not be published. Required fields are marked *