Install and Configure GitLab on Rocky Linux 8: Easy Steps To Host Git Repos

Posted on

Install and Configure GitLab on Rocky Linux 8: Easy Steps To Host Git Repos

Install and Configure GitLab on Rocky Linux 8: Easy Steps To Host Git Repos

This guide on the Orcacore website will teach you how to Install and Configure GitLab on Rocky Linux 8. GitLab CE, or Community Edition, is a powerful open-source application ideal for hosting your Git repositories. It provides the distinct advantage of maintaining your data securely on your own server, offering total control over your codebase while offering an intuitive interface for you and your team. Install and Configure GitLab on Rocky Linux 8 successfully with this guide.

Before you begin, ensure you have the following prerequisites in place: you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. Refer to our guide on Initial Server Setup with Rocky Linux 8 for assistance.

Additionally, you will require a domain name pointed to your server’s IP address.

1. Required Packages For GitLab Setup

First, update your local package index using the following command:

sudo dnf update -y

Next, install the necessary dependencies and required packages with this command:

sudo dnf install curl vi policycoreutils python3-policycoreutils git -y

2. Install GitLab on Rocky Linux 8

The GitLab repository is not included in the default Rocky Linux repositories. Therefore, you must manually add it to your server.

Add GitLab Repository

Create and open the GitLab repository file using your preferred text editor. Here, we utilize the vi editor:

sudo vi /etc/yum.repos.d/gitlab_gitlab-ce.repo

Add the following content to the file:

[gitlab_gitlab-ce]
name=gitlab_gitlab-ce
baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/8/$basearch
repo_gpgcheck=1
gpgcheck=1
enabled=1
gpgkey=https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey
       https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey/gitlab-gitlab-ce-3D645A26AB9FBD22.pub.gpg
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[gitlab_gitlab-ce-source]
name=gitlab_gitlab-ce-source
baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/8/SRPMS
repo_gpgcheck=1
gpgcheck=1
enabled=1
gpgkey=https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey
       https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey/gitlab-gitlab-ce-3D645A26AB9FBD22.pub.gpg
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

Save and close the file after adding the content.

Verify that the GitLab repository has been successfully added to your Rocky Linux server:

dnf repolist
Gitlab repository Rocky Linux 8

GitLab CE Installation on Rocky Linux 8

Now, use the following command to Install and Configure GitLab on Rocky Linux 8 CE (Community Edition) on your server:

sudo dnf install gitlab-ce -y

3. Configure GitLab CE on Rocky Linux 8

Next, you need to modify the GitLab configuration file. Open the file with your preferred text editor (vi in this case):

sudo vi /etc/gitlab/gitlab.rb

Locate the external_url configuration line and update it to reflect your domain. Remember to change http to https to automatically redirect users to the site secured by the Let’s Encrypt certificate.

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

Also, find the line below, uncomment it by removing the "#", and set your email address:

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

Save and close the file when finished.

Reconfigure GitLab

Run the following command to reconfigure GitLab on Rocky Linux 8:

sudo gitlab-ctl reconfigure

This command initializes GitLab using the information available about your server. It also configures a Let’s Encrypt certificate for your domain.

This process will take some time to complete.

Upon completion, you should see the following output:

Output
gitlab Reconfigured!

Configure Firewall for GitLab

Allow HTTP/HTTPS and SSH services through the firewall:

sudo firewall-cmd --permanent --add-service={ssh,http,https} --permanent

Reload the firewall to apply the changes:

sudo firewall-cmd --reload

4. Access GitLab Dashboard Web Interface

You can now continue configuring GitLab on Rocky Linux 8 through the web interface. Type your domain name into your web browser:

https://your_domain

This will display the GitLab Community Edition Login page.

GitLab Initial Password

Note: GitLab generates an initial secure password for you. This password is stored in a file accessible to administrative sudo users:

sudo cat /etc/gitlab/initial_root_password

The output should resemble the following:

Password: Kei6i+7QSMZP7mmIrYM+jCuWot0d3bV4FvsHISYQfk8=

On the GitLab login page, enter root as the username and the generated initial password as the password. Click Sign in.

GitLab login screen
GitLab Login

After successful login, you will be redirected to the GitLab dashboard, where you can begin adding projects.

GitLab dashboard
GitLab Dashboard

From the dashboard, you can update your password, adjust profile settings, change your account name, add an SSH key to your account, and more.

5. Renew Certificates for GitLab on Rocky Linux 8

GitLab automatically schedules a task to renew Let’s Encrypt certificates after midnight every fourth day, with the exact minute determined by your external_url.

You can customize these settings by editing the GitLab configuration file:

sudo vi /etc/gitlab/gitlab.rb

Locate the following lines in the file, remove the #, and modify them as follows:

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

This configuration will renew your certificates every 7th day at 12:30. Adjust the values as needed.

Disable Auto-Renewal Certificate

Alternatively, you can disable automatic renewal by setting letsencrypt['auto_renew'] to false:

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

Save and close the file after making any changes.

Conclusion

Congratulations! You have successfully learned to Install and Configure GitLab on Rocky Linux 8. GitLab offers a seamless experience for hosting your Git repositories.

We hope you find it beneficial. You may also be interested in these articles:

Install Cinnamon Desktop Environment on Rocky Linux 8

How To Install PHP 7.4 on Rocky Linux 8

Set up Redis on Rocky Linux 9

Anaconda Installation on Rocky Linux 8

GCC Compiler Setup Rocky Linux 8

Squid Proxy Server Rocky Linux 8

LibreNMS Setup on Rocky Linux 8

Use Iptables on Rocky Linux 8

Alternative Solutions for Installing GitLab on Rocky Linux 8

While the above steps provide a comprehensive guide on how to Install and Configure GitLab on Rocky Linux 8 directly on your server, here are two alternative approaches that you might consider:

1. Using Docker Compose:

Docker provides a containerization platform that simplifies application deployment. Using Docker Compose allows you to define and manage multi-container Docker applications. This approach offers several advantages, including portability, isolation, and ease of management.

Instead of directly installing GitLab on your Rocky Linux 8 server, you can run it inside a Docker container. Here’s how:

  • Install Docker and Docker Compose: If you haven’t already, install Docker and Docker Compose on your Rocky Linux 8 server.

    sudo dnf install docker -y
    sudo systemctl start docker
    sudo systemctl enable docker
    
    sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose
  • Create a docker-compose.yml file: Create a docker-compose.yml file in a directory of your choice. This file will define the GitLab service and its dependencies.

    version: '3.6'
    
    services:
      gitlab:
        image: 'gitlab/gitlab-ce:latest'
        restart: always
        hostname: 'gitlab.example.com' # Replace with your hostname
        environment:
          GITLAB_OMNIBUS_CONFIG: |
            external_url 'https://gitlab.example.com' # Replace with your URL
            gitlab_rails['gitlab_shell_ssh_port'] = 2224 # If using a different SSH port
        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'
        shm_size: '256m'

    Explanation:

    • image: Specifies the GitLab CE Docker image.
    • restart: Ensures the container restarts automatically if it crashes.
    • hostname: Sets the hostname for the GitLab instance.
    • environment: Defines environment variables to configure GitLab. GITLAB_OMNIBUS_CONFIG allows you to set GitLab configuration options.
    • ports: Maps ports from the container to the host machine. Important: Change the host ports if they conflict with other services.
    • volumes: Mounts directories on the host machine to the container, preserving data across container restarts. Change /srv/gitlab to a different path if you prefer.
    • shm_size: Allocates shared memory for the container, which can improve performance.
  • Run Docker Compose: Navigate to the directory containing the docker-compose.yml file and run the following command:

    docker-compose up -d

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

  • Access GitLab: After the container starts, you can access GitLab through your configured domain or IP address. Note that the initial setup might take a few minutes.

2. Using a Cloud Provider’s Managed GitLab Service:

Many cloud providers, such as AWS, Google Cloud, and Azure, offer managed GitLab services. These services handle the installation, configuration, maintenance, and scaling of GitLab, allowing you to focus on your development workflow.

  • Benefits of a Managed Service:

    • Simplified Management: The cloud provider handles the complexities of GitLab administration.
    • Scalability: Easily scale your GitLab instance as your needs grow.
    • High Availability: Benefit from the provider’s infrastructure and redundancy.
    • Automatic Updates: The service is automatically updated with the latest GitLab releases.
    • Security: Leverage the provider’s security expertise and infrastructure.
  • Example using Google Cloud’s Cloud Source Repositories (with GitLab integration):

    While not a fully-managed GitLab instance, Google Cloud Source Repositories integrates well with existing GitLab workflows. You can host your code on Google Cloud and then connect it to a GitLab instance running elsewhere for CI/CD and other features. This provides a hybrid approach where you benefit from Google Cloud’s infrastructure and GitLab’s tooling. Other cloud providers have similar solutions. Look for services that offer Git hosting with integrations for popular CI/CD platforms.

    The setup varies depending on the cloud provider you choose. Refer to the provider’s documentation for specific instructions.

These alternative solutions offer different trade-offs in terms of control, complexity, and cost. Choose the option that best aligns with your requirements and technical expertise. While this guide focuses on how to Install and Configure GitLab on Rocky Linux 8, remember that cloud services and Docker provide valid routes to running a Git repository.

Leave a Reply

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