How to Install and Configure GitLab on CentOS 8/7?


GitLab is an open-source platform that allows you to manage your source code repositories and collaborate with your team members. With GitLab, you can host your Git repositories, manage code reviews, automate CI/CD pipelines, and much more. In this article, we will guide you through process of installing and configuring GitLab on CentOS 8/7.

Before we start with installation, there are a few prerequisites that you need to fulfill −

Prerequisites

  • A CentOS 8/7 server with a minimum of 4GB of RAM and 2 CPU cores.

  • A domain name pointing to server's IP address.

  • A valid SSL certificate for domain name.

  • A root or sudo user account.

Step 1: Update System

The first step is to update system packages to their latest version. You can do this by running following command −

sudo yum update

Step 2: Install and Configure Dependencies

Next, we need to install some dependencies that are required for GitLab to work properly. Run following command to install them −

sudo yum install -y curl policycoreutils-python openssh-server openssh-clients

Once installation is complete, we need to configure firewall to allow SSH and HTTP traffic. Run following commands to do so −

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

Step 3: Install GitLab

Now we are ready to install GitLab. We will use official GitLab Omnibus package to install GitLab. Run following command to download and install GitLab −

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="https://your-domain-name.com" yum install -y gitlab-ee

Replace "your-domain-name.com" with your actual domain name.

The installation process may take some time, depending on your server's speed and your internet connection. Once installation is complete, you will see a message that says "GitLab has been installed".

Step 4: Configure GitLab

Now that GitLab is installed, we need to configure it to work properly. Open GitLab configuration file using your favorite text editor −

sudo nano /etc/gitlab/gitlab.rb

In this file, you can configure various settings such as SMTP server, backup location, and much more. For now, we will only configure external URL and SSL certificate.

Find following lines in file −

# external_url 'http://gitlab.example.com'
# nginx['redirect_http_to_https'] = true
# nginx['redirect_http_to_https_port'] = 80

Uncomment first line and replace "http://gitlab.example.com" with your actual domain name. Uncomment second and third lines to enable HTTP to HTTPS redirection. Your configuration should look like this −

external_url 'https://your-domain-name.com'
nginx['redirect_http_to_https'] = true
nginx['redirect_http_to_https_port'] = 80

Save and close file.

Step 5: Install SSL Certificate

GitLab requires a valid SSL certificate to work properly. If you don't have an SSL certificate, you can obtain a free one from Let's Encrypt.

First, install Certbot client by running following command −

sudo yum install -y certbot python3-certbot-nginx

Next, run following command to obtain SSL certificate −

sudo certbot --nginx -d your-domain-name.com

Follow instructions to obtain SSL certificate. Once certificate is installed, reload nginx configuration by running following command −

sudo gitlab-ctl reconfigure

Step 6: Access GitLab

Now that GitLab is installed and configured, you can access it by navigating to your domain name in your web browser. If everything was configured correctly, you should see GitLab login page.

The default login credentials for GitLab are −

Username: root
Password: 5iveL!fe

We recommend changing default password as soon as you log in to GitLab.

Step 7: Configure GitLab Runner

GitLab Runner is an application that runs jobs in response to GitLab CI/CD pipelines. By default, GitLab Runner is not installed on your server. You can install it by following official documentation.

Once GitLab Runner is installed, you need to register it with GitLab. Open a terminal on your server and run following command −

sudo gitlab-runner register

Follow instructions to register GitLab Runner with GitLab.

Here are some additional steps you can take to further configure and customize your GitLab installation −

Configure GitLab Backup

It is important to regularly backup your GitLab data to avoid losing any valuable data. GitLab provides a built-in backup utility that you can configure to run automatically. To do this, open GitLab configuration file using your favorite text editor −

sudo nano /etc/gitlab/gitlab.rb

Find following line in file −

# gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

Uncomment line and specify a backup directory. Save and close file.

Next, run following command to configure backup −

sudo gitlab-ctl reconfigure

Finally, run following command to create a backup of your GitLab data −

sudo gitlab-rake gitlab:backup:create

Configure GitLab SMTP

GitLab allows you to configure SMTP settings so that you can send emails from your GitLab instance. To do this, open GitLab configuration file using your favorite text editor −

sudo nano /etc/gitlab/gitlab.rb

Find following lines in file −

# gitlab_rails['smtp_enable'] = true
# gitlab_rails['smtp_address'] = "smtp.gmail.com"
# gitlab_rails['smtp_port'] = 587
# gitlab_rails['smtp_user_name'] = "user@gmail.com"
# gitlab_rails['smtp_password'] = "password"
# gitlab_rails['smtp_domain'] = "smtp.gmail.com"
# gitlab_rails['smtp_authentication'] = "login"
# gitlab_rails['smtp_enable_starttls_auto'] = true
# gitlab_rails['smtp_tls'] = false

Uncomment lines and replace SMTP settings with your own settings. Save and close file.

Next, run following command to configure GitLab with new SMTP settings −

sudo gitlab-ctl reconfigure

Configure GitLab LDAP

If you use LDAP to manage user authentication, you can configure GitLab to use LDAP for authentication as well. To do this, open GitLab configuration file using your favorite text editor −

sudo nano /etc/gitlab/gitlab.rb

Find following lines in file −

# gitlab_rails['ldap_enabled'] = false
# gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
#   main:
#      label: 'LDAP'
#      host: '_your_ldap_server'
#      port: 389
#      uid: 'sAMAccountName'
#      bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
#      password: '_the_password_of_the_bind_user'
#      encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
#      verify_certificates: true
#      smartcard_auth: false
#      active_directory: true
#      allow_username_or_email_login: false
#      lowercase_usernames: false
#      block_auto_created_users: false
#      base: '_the_full_dn_of_the_search_base'
#      user_filter: ''
# EOS

Uncomment lines and replace LDAP settings with your own settings. Save and close file.

Next, run following command to configure GitLab with new LDAP settings −

sudo gitlab-ctl reconfigure

Install GitLab Plugins

GitLab allows you to install plugins to extend its functionality. You can browse and install GitLab plugins from the GitLab marketplace. To install a plugin, log in to your GitLab instance and navigate to Admin area. From there, click on "Plugins" and then click on "Marketplace".

You can browse available plugins and click on "Install" to install a plugin. Once a plugin is installed, you may need to configure it by clicking on "Settings" and following instructions provided by plugin.

Customize GitLab Appearance

GitLab allows you to customize its appearance by adding a logo and changing color scheme. To add a logo, log in to your GitLab instance and navigate to Admin area. From there, click on "Appearance" and then click on "Custom logos".

You can upload a logo and adjust its size and position. To change color scheme, click on "Colors" and select a color theme. You can also customize CSS by clicking on "Custom CSS" and adding your own CSS.

Configure GitLab Omnibus Settings

GitLab Omnibus provides a rich set of configuration options that can be used to customize your GitLab installation. You can configure various settings related to GitLab, Nginx, PostgreSQL, Redis, and more. To see a list of available configuration options, run following command −

sudo gitlab-ctl show-config

This will display full configuration for your GitLab installation.

To customize GitLab Omnibus settings, open GitLab configuration file using your favorite text editor −

sudo nano /etc/gitlab/gitlab.rb

Here, you can uncomment and modify any of available settings to customize your GitLab installation.

Configure GitLab Container Registry

GitLab provides a built-in container registry that can be used to store and manage Docker images. To enable GitLab container registry, open GitLab configuration file using your favorite text editor −

sudo nano /etc/gitlab/gitlab.rb

Find following line in file −

# gitlab_rails['registry_enabled'] = false

Uncomment line to enable GitLab container registry. Save and close file.

Next, run following command to reconfigure GitLab −

sudo gitlab-ctl reconfigure

Once GitLab container registry is enabled, you can use it to store and manage Docker images. You can follow official documentation to learn more about how to use GitLab container registry.

Conclusion

Congratulations! You have successfully installed and configured GitLab on CentOS 8/7. GitLab is a powerful tool that can help you manage your source code repositories and streamline your development process. With GitLab, you can collaborate with your team members, automate your CI/CD pipelines, and much more.

We hope this article was helpful in guiding you through installation and configuration process. If you encounter any issues or have any questions, feel free to reach out to GitLab community for support.

Updated on: 12-May-2023

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements