How to Install GitLab on Ubuntu 18.04/16.04 LTS

In this article, We are going to perform How to Install GitLab on Ubuntu 18.04/16.04 LTS or any other cloud platform like Amazon EC2, Azure VM, Google Compute Cloud, etc., with preinstalled Ubuntu OS.

Introduction:

GitLab is an open source, cloud-based Git repository and version control system.

Prerequisite

  • Processor- minimum i3
  • Storage –    480 GB SSD
  • Ram-         8 GB(upto 200 Users)
  • OS-           Ubuntu 18.04/16.04 LTS

update the System Packages

$ sudo apt-get update
$ sudo apt-get upgrade

Install Dependencies Packages

Install below dependencies packages

$ sudo apt-get install -y curl openssh-server ca-certificates

Install Postfix to send email notifications

If you want to use another solution to send emails please skip this step and configure an external SMTP server after GitLab has been installed.

$ sudo apt-get install -y postfix

During Postfix installation a configuration screen may appear.

Select ‘Internet Site’ and press Enter.

Use your server’s external DNS for ‘mail name’ and press Enter.

If additional screens appear, continue to press Enter to accept the defaults.

Install GitLab on Ubuntu

Add the GitLab package repository. Here we are installing omnibus packages and Free Enterprise Edition

$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash

After installing gitlab packages, Change https://gitlab.example.com to the URL at which you want to access your GitLab instance. Installation will automatically configure and start GitLab at that URL.

Check the status if GitLab Service running

$ sudo gitlab-ctl status

Generate Let’s Encrypt SSL

Create the /etc/gitlab/ssl directory and generate your key and certificate there:

$ sudo mkdir -p /etc/gitlab/ssl

Change the folder permission.

$ sudo chmod 700 /etc/gitlab/ssl

Go Inside SSL directory and run below command

$ openssl genrsa -out gitlab. devopskloud.tech.key 2048

$ openssl req -new -key gitlab.devopskloud.tech.key -out gitlab.devopskloud.tech.crt

Download SSL and copy inside /etc/gitlab/ssl directory

Adding SSL and Secure GitLab Server with SSL Certificate

once you copied SSL certificates to /etc/gitlab/ssl directory, here you can add OpenSSL or commercial domain certificates also.

First change the permission of ssl directory

$ sudo chmod 600 /etc/gitlab/ssl/*

Open GitLab configuration /etc/gitlab/gitlab.rb, change the external_url and add domain key, cert file as shown below

/etc/gitlab/gitlab.rb
external_url 'https://gitlab.devopskloud.tech'

nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.devopskloud.tech.crt"

nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.devopskloud.tech.key"

Run the below command to take effect

$ sudo gitlab-ctl reconfigure

Redirect HTTP requests to HTTPS in Nginx

By default, when you specify an external_url starting with ‘https’, NGINX will no longer listen for unencrypted HTTP traffic on port 80. If you want to redirect all HTTP traffic to HTTPS you can use the redirect_http_to_https setting.

Edit /etc/gitlab/gitlab.rb and add below line after “external_url ” https://gitlab.devopskloud.tech ” line.

nginx['redirect_http_to_https'] = true

Run the below command to take effect

$ sudo gitlab-ctl reconfigure

Enable firewall Rule

Enable the SSH, http and https service into Ubuntu UFW Firewall,

$ sudo ufw allow ssh
$ sudo ufw allow http
$ sudo ufw allow https

Check the Firewall Status

$ sudo ufw status

If you using cloud instance the allow above services in inbound rules.

Access GitLab Web Interface

On your first visit, you’ll be redirected to a password reset screen. Provide the password for the initial administrator account and you will be redirected back to the login screen.

Use the default account’s username root to login

https://domain_name_or_server_IP

login to gitlab server with username and password

Successfully we have performed Install GitLab on Ubuntu 18.04/16.04 LTS

Configure Office365 SMTP Settings in GitLab

Open GitLab configuration /etc/gitlab/gitlab.rb, Goto GitLab email server settings and change SMTP settings as shown below

/etc/gitlab/gitlab.rb
### GitLab email server settings

###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html

###! **Use smtp instead of sendmail/postfix.**

gitlab_rails['smtp_enable'] = true

gitlab_rails['smtp_address'] = 'smtp.office365.com';

gitlab_rails['smtp_port'] = 587;

gitlab_rails['smtp_domain'] = 'devopskloud.tech';

gitlab_rails['smtp_openssl_verify_mode'] = 'peer'

gitlab_rails['smtp_enable_starttls_auto'] = true

gitlab_rails['smtp_user_name'] = "[email protected]"

gitlab_rails['smtp_password'] = "*********"

gitlab_rails['smtp_authentication'] = "login"

gitlab_rails['gitlab_email_from'] = '[email protected]'

gitlab_rails['gitlab_email_reply_to'] = '[email protected]'

Run the below command to take effect

$ sudo gitlab-ctl reconfigure

Start/Stop/Restart GitLab Server

Below are commands to Start/Stop/Restart GitLab Server.

$ sudo gitlab-ctl start

$ sudo gitlab-ctl stop

$ sudo gitlab-ctl restart

GitLab Project Data Migration from Old Server to New Server

  • Create Same project under same Group
  • Add existing project member on new server and give respective project access.
  • You should be member of old project and new project
  • Clone old Gitlab Project on your local system with below mirroring clone method
  • git clone –mirror OLD-URL
  • Once clone will be done go inside the respective project directory and run below command for data push on new server.
  • git push –mirror NEW-REMOTE

Conclusion

In this article, We have covered install GitLab on Ubuntu, generated SSL certificates, Adding SSL and Secure GitLab Server with SSL Certificate and redirected http to https in nginx,enabled firewall rules in Ubuntu .

Related Articles

7 Steps for GitLab Runner Registration

Angular CI CD Pipeline with GitLab in 6 Easy Steps

GitLab CI CD Pipeline for php,Drupal,Python Application

Git Tutorial

Mahesh Karale

I am Mahesh Karale working as DevOps Engineer. Likes to Explore and Research on Linux, Cloud and DevOps Tools.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap