Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
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 the process of installing and configuring GitLab on CentOS 8/7.
Prerequisites
Before we start with the installation, there are a few prerequisites that you need to fulfill
A CentOS 8/7 server with a minimum of 4GB of RAM and 2 CPU cores.
A domain name pointing to the server's IP address.
A valid SSL certificate for the 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 the 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 the following command to install them
sudo yum install -y curl policycoreutils-python openssh-server openssh-clients
Once the installation is complete, we need to configure the firewall to allow SSH and HTTP traffic. Run the 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 the official GitLab Omnibus package to install GitLab. Run the 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 the 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 the 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 the external URL and SSL certificate.
Find the following lines in the file
# external_url 'http://gitlab.example.com' # nginx['redirect_http_to_https'] = true # nginx['redirect_http_to_https_port'] = 80
Uncomment the first line and replace http://gitlab.example.com with your actual domain name. Uncomment the 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 the 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 the Certbot client by running the following command
sudo yum install -y certbot python3-certbot-nginx
Next, run the following command to obtain the SSL certificate
sudo certbot --nginx -d your-domain-name.com
Follow the instructions to obtain the SSL certificate. Once the certificate is installed, reload the nginx configuration by running the 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 the GitLab login page.
The default login credentials for GitLab are
Username: root Password: 5iveL!fe
We recommend changing the default password as soon as you log in to GitLab.
Additional Configuration Options
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 the GitLab configuration file
sudo nano /etc/gitlab/gitlab.rb
Find the following line in the file
# gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
Uncomment the line and specify a backup directory. Save and close the file. Run the following command to reconfigure GitLab
sudo gitlab-ctl reconfigure
Finally, run the 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. Open the GitLab configuration file and find the SMTP settings
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
Replace the SMTP settings with your own configuration. After saving the file, run sudo gitlab-ctl reconfigure to apply the changes.
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 the configuration file and find
# gitlab_rails['registry_enabled'] = false
Uncomment the line and set it to true to enable the GitLab container registry. Save the file and run sudo gitlab-ctl reconfigure to apply the changes.
Conclusion
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 proper configuration of backups, SMTP, and additional features, your GitLab instance is ready for production use.
