Quantcast
Channel: Pradeep Kumar
Viewing all articles
Browse latest Browse all 461

How to Install and Configure GitLab CE on Ubuntu 18.04 / 16.04 Sever

$
0
0

GitLab CE(Community Edition) is a free and opensource is git manager tool, it provides a beautiful graphical user interface and allows us to manage all our git repositories from the centralized server.

GitLab CE is generally used for Software development teams, where coders can check-in and checkout their latest code, it can also be used for version control, Code review and CI/CD(Continues Integration / Continues Development) approach.

In this article we will demonstrate how to install latest version of GitLab CE on Ubuntu 18.04 / 16.04 Server. Below are my Lab Setup details:

  • IP Address of Ubuntu Server (18.04 /16.04) : 192.168.0.104
  • Hostname of Ubuntu Server: gitlabce.example.com
  • RAM : 2GB ( Though Gitlab recommends 4 GB for Gitlab Setup)

1) Install Gitlab dependencies using apt command

Login to your Ubuntu 16.04 / 18.04 server and run the following apt commands to install gitlab dependencies,

linuxtechi@gitlabce:~$ sudo apt update
linuxtechi@gitlabce:~$ sudo apt install curl openssh-server ca-certificates postfix -y

Above command will prompt you how you want to configure Postfix sever, select the option which suits to your environment.

2) Setup GitLab CE package repository via script

Run the below curl command, which will download the gitlab-ce script and will configure package repository

linuxtechi@gitlabce:~$ curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

Output of above curl command would be something like below:

GitLab-CE-Package-Repository

3) Install GitLab CE package using apt command

Run the beneath command to install and configure gitlab-ce  on your server automatically, replace the server’s hostname as your setup,

linuxtechi@gitlabce:~$ sudo EXTERNAL_URL="http://gitlabce.example.com" apt-get install gitlab-ce

Once the above the command is executed successfully, we will get output something like below,

GitLab-CE-Installion-Message

Note : If OS firewall is enabled on your server, then allow 80 and 443 ports, on Ubuntu Servers ufw is default firewall,

linuxtechi@gitlabce:~$ sudo ufw allow http
Rule added
Rule added (v6)
linuxtechi@gitlabce:~$ sudo ufw allow https
Rule added
Rule added (v6)
linuxtechi@gitlabce:~$

4) Access GitLab Server from Web browser

Open your favorite web browser and type the url http://gitlabce.example.com

First time , it prompt us to set the password, so specify the password and the click on “Change your password”

GitLab-CE-Password-Set-Screen

In next screen we will get the below screen, Now login with the user name with “root” and the password that we have set in above step,

Login-GitLab-CE-GUI

Click on “Sign in”

Dashboard -GitLab-Ubuntu-18-04

As of now our GitLab Server is working on http (80) protocol, if you want to enable https for your GitLab portal, then refer the below step,

5) Configure https for your GitLab Server

All the important configuration for Gitlab server is controlled by the file “/etc/gitlab/gitlab.rb” So edit this file,  search “external_url” and add the “gitlabce.example.com” in front of external_url parameter

linuxtechi@gitlabce:~$ sudo vi /etc/gitlab/gitlab.rb
----------------------------------------------------------
external_url 'https://gitlabce.example.com'
----------------------------------------------------------

Save and exit the file,

Now let’s create following folder and generate self-sign certificates using openssl command

linuxtechi@gitlabce:~$ sudo mkdir -p /etc/gitlab/ssl
linuxtechi@gitlabce:~$ sudo chmod 700 /etc/gitlab/ssl

Let first generate the private key using openssl command,

linuxtechi@gitlabce:~$ sudo openssl genrsa -des3 -out /etc/gitlab/ssl/gitlabce.example.com.key 2048

Enter the passphrase and and remember it

Create the CSR using below command,

linuxtechi@gitlabce:~$ sudo openssl req -new -key /etc/gitlab/ssl/gitlabce.example.com.key -out /etc/gitlab/ssl/gitlabce.example.com.csr
Enter pass phrase for /etc/gitlab/ssl/gitlabce.example.com.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:Delhi
Locality Name (eg, city) []:Delhi
Organization Name (eg, company) [Internet Widgits Pty Ltd]:LinuxTechi
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:gitlabce.example.com
Email Address []:info@linuxtechi.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
linuxtechi@gitlabce:~$

Remove Passphrase from the key

Run the following commands one after the another

linuxtechi@gitlabce:~$ sudo cp -v /etc/gitlab/ssl/gitlabce.example.com.{key,original}
'/etc/gitlab/ssl/gitlabce.example.com.key' -> '/etc/gitlab/ssl/gitlabce.example.com.original'
linuxtechi@gitlabce:~$
linuxtechi@gitlabce:~$ sudo openssl rsa -in /etc/gitlab/ssl/gitlabce.example.com.original -out /etc/gitlab/ssl/gitlabce.example.com.key
Enter pass phrase for /etc/gitlab/ssl/gitlabce.example.com.original:
writing RSA key
linuxtechi@gitlabce:~$
linuxtechi@gitlabce:~$ sudo rm -v /etc/gitlab/ssl/gitlabce.example.com.original
removed '/etc/gitlab/ssl/gitlabce.example.com.original'
linuxtechi@gitlabce:~$

Create the Certificate using below openssl command,

linuxtechi@gitlabce:~$ sudo openssl x509 -req -days 1460 -in /etc/gitlab/ssl/gitlabce.example.com.csr -signkey /etc/gitlab/ssl/gitlabce.example.com.key -out /etc/gitlab/ssl/gitlabce.example.com.crt

Remove the CSR file using below rm command,

linuxtechi@gitlabce:~$ sudo rm -v /etc/gitlab/ssl/gitlabce.example.com.csr
removed '/etc/gitlab/ssl/gitlabce.example.com.csr'
linuxtechi@gitlabce:~$

Set the below permissions on Key and Certificate

linuxtechi@gitlabce:~$ sudo chmod 600 /etc/gitlab/ssl/gitlabce.example.com.key
linuxtechi@gitlabce:~$ sudo chmod 600 /etc/gitlab/ssl/gitlabce.example.com.crt

Reconfigure the gitlab using below command

linuxtechi@gitlabce:~$ sudo gitlab-ctl reconfigure

Once above command is executed successfully, then your GitLab portal should be accessible over https protocol, In my case url will be: https://gitlabce.example.com/

When you access it first time, it will say something like your connection is not secure, click on “Add-Exception..”

Https-GitLab-Dashboard

6) Create a test Project and perform basic git operations

Let’s create a test project with name “linuxrocks“, click on “Create a project” option from GitLab dashboard,

New-Project-GitLab-Ubuntu-18-04

Specify the Project and its description and then click on “Create project”

GitLab-Dashboard-Linuxrocks-Project-Ubuntu18-04

Now Let’s clone the repository of “linuxrocks” project using the following commands,

root@gitlabce:~# git config --global user.name "Administrator"
root@gitlabce:~# git config --global user.email admin@gitlabce.example.com
root@gitlabce:~# export GIT_SSL_NO_VERIFY=1
root@gitlabce:~# git clone https://gitlabce.example.com/root/linuxrocks.git
Cloning into 'linuxrocks'...
Username for 'https://gitlabce.example.com': root
Password for 'https://root@gitlabce.example.com':
warning: You appear to have cloned an empty repository.
root@gitlabce:~# ls
linuxrocks
root@gitlabce:~# cd linuxrocks
root@gitlabce:~/linuxrocks# touch linux-distributions.txt
root@gitlabce:~/linuxrocks# git add linux-distributions.txt
root@gitlabce:~/linuxrocks# git commit -m "add linux-distributions"
[master (root-commit) 3a72b57] add linux-distributions
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 linux-distributions.txt
root@gitlabce:~/linuxrocks# git push -u origin master
Username for 'https://gitlabce.example.com': root
Password for 'https://root@gitlabce.example.com':
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 238 bytes | 238.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://gitlabce.example.com/root/linuxrocks.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
root@gitlabce:~/linuxrocks#

Now go to the GitLab dashboard and see whether new file has been pushed under “linuxrocks” project

Files-Projects-Gitlab-Dashboard-Ubuntu18-04

That’s conclude our article, there are plenty of things that can be configured, but that is not feasible to discuss in this tutorial. I hope this article helps you to install latest version of GitLab on your Ubuntu Servers, please do share your feedback and comments.


Viewing all articles
Browse latest Browse all 461

Trending Articles