Você está na página 1de 16

How

to Install and Configure GitLab on Ubuntu


18.04 LTS

GitLab is an open source GIT repository manager based on Rails and developed by
GitLab Inc. It is a web-based GIT repository manager that allows your team to work
on code, perform feature requests, track bugs, and test and implement applications.
GitLab provides features such as a wiki, issue tracking, code reviews, activity feeds,
and merge management. It is able to host multiple projects.

GitLab is available in four editions:

Gitlab CE (Community Edition) - self-hosted, free and support from the Community
forum.
Gitlab EE (Enterprise Edition) - self-hosted, paid app, comes with additional
features.
GitLab.com - SaaS, free.
GitLab.io - Private GitLab instance managed by GitLab Inc.

In this tutorial, I will show you step-by-step how to install GitLab CE (Community
Edition) on your own Ubuntu 18.04 LTS (Bionic Beaver) server. I will be using the
'omnibus' package provided by GitLab for easy installation.

Prerequisites
Ubuntu 18.04 Server
Min RAM memory 4GB - for better performance, use 8GB
Root privileges

What we will do
Update Repository and Upgrade Packages
Install Dependencies
Install GitLab Community Edition
Generate SSL Letsencrypt and DHPARAM Certificate
Configure HTTPS for GitLab
Configure Ubuntu UFW Firewall
GitLab Post-Installation
Testing

Step 1 - Update Repository and Upgrade Packages

Before installing any packages on the system, update all available repositories and
then upgrade all packages on the system.
Run apt commands below.

sudo apt update


sudo apt upgrade y

Wait for the installation packages that will be upgraded.

Step 2 - Install Gitlab Dependencies

GitLab needs some packages dependencies for the installation, including curl,
postfix, and ca-certificates.

Install GitLab packages dependencies using the apt command below.

sudo apt install curl openssh server ca certificates postfix


y

During postfix installation, you will be prompted about the configuration, select
'Internet Site'.
And then enter the server domain name that shall be used for sending an email.

And we're ready to install GitLab on the server.

Step 3 - Install GitLab

In this step, we will install GitLab using the omnibus packages. The Omnibus will
install all packages, services, and tools required for running GitLab on the server.

Add GitLab repository with the curl command.

curl sS https: packages.gitlab.com/install/repositories/git


lab/gitlab ce/script.deb.sh | sudo bash
And then install GitLab CE Community Edition with the apt command.

sudo apt install gitlab ce y

The command will download and install the GitLab CE package, and when the
installation is complete, you will see the results as below.

Next, we should configure the URL that will be used to access our GitLab server. We
will be using a domain named 'git.hakase-labs.pw' for the GitLab access URL and
will enable the HTTPS on it.

To change the GitLab URL access, edit the '/etc/gitlab/gitlab.rb' file.

sudo vim /etc/gitlab/gitlab.rb


Now change the 'external_url' value with your own domain name.

external_url 'http: git.hakase labs.pw'

Save and exit.

Step 4 - Generate Let's encrypt SSL Certificate and


DHPARAM Certificate

In this step, we will generate a new Letsencrypt certificate and DHPARAM certificate
for the GitLab domain name 'git.hakase-labs.pw'.

Install the lets encrypt tool using the apt command below.

sudo apt install letsencrypt y

And after the installation is complete, run the letsencrypt command below.

sudo letsencrypt certonly standalone agree tos no eff e


mail agree tos email tensaitux993@gmail.com d git.hakase
labs.pw

And when it's complete, you will get the result as shown below.

SSL Letsencrypt certificates have been generated, located in the '/etc/letsencyrpt/'


directory.

Next, we will generate the DHPARAM certificate using the OpenSSL command.
Create a new directory '/etc/gitlab/ssl' and run the OpenSSL command below.

sudo mkdir p /etc/gitlab/ssl/


sudo openssl dhparam out /etc/gitlab/ssl/dhparams.pem 2048

Now change the permission of the SSL directory.

chmod 600 /etc/gitlab/ssl

And all certificates needed for GitLab HTTPS configuration have been generated.

Step 5 - Configure HTTPS for GitLab

In order to enable the HTTPS for GitLab installation, we need to edit the 'gitlab.rb'
file.

Edit the '/etc/gitlab/gitlab.rb' file using the vim command below.

sudo vim /etc/gitlab/gitlab.rb

Change the 'external_url' of Gitlab to the 'https://git.hakase-labs.pw'.

external_url 'https: git.hakase labs.pw'

Now paste configuration below to the '#GitLab Nginx' section.

nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/letsencrypt/live/git.hakase-la
bs.pw/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/git.hakas
e-labs.pw/privkey.pem"
nginx['ssl_dhparam'] = "/etc/gitlab/ssl/dhparams.pem"

Save and exit.

Now run the 'gitlab-ctl' command below.

sudo gitlab ctl reconfigure

This command will install and configure GitLab based on the '/etc/gitlab/gitlab.rb'
configuration file.

And when it's complete, you will see the result as below.

The GitLab installation is complete, and HTTPS for GitLab has been enabled.
Step 6 - Configure Ubuntu UFW Firewall

In this step, we will enable the Ubuntu UFW firewall. It's already installed on the
system, we just need to start the service. We will run GitLab behind the Ubuntu
UFW firewall, so we must open the HTTP and HTTPS ports.

Add ssh, http, and https services to the configuration.

sudo ufw allow ssh


sudo ufw allow http
sudo ufw allow https

And enable the Ubuntu UFW firewall with the command below.

sudo ufw enable

Type 'y' for yes to enabled it.

Now check all services and ports list on the list.

sudo ufw status

And you will get ssh, http, and https services on the list.
Step 7 - GitLab Post-Installation

Open the web browser and type in the gitlab URL 'git.hakase-labs.pw', and you will
be redirected to the HTTPS connection.

Create a New GitLab Root Password

Type your new password for root GitLab user, and click the 'Change your password'
button.

Now Login as a 'root' user with your own password and click the 'Login' button.
Now you will get the GitLab Dashboard.

Change Profile

Click the profile button and choose 'Settings'.


On the 'Main Settings' section, type the profile name 'hakase' and then click the
'update profile settings' option.

Change Username

Click the 'Account' tab and type the username 'hakase'.

Now press the 'Update username' button.

Add SSH Key

Generate a new key using the ssh-keygen command as below.

ssh keygen
cat ~/.ssh/id_rsa.pub
Copy the 'id_rsa.pub' key.

Now back to the GitLab user dashboard and click the 'SSH Key' menu on the left.

Paste the ssh public key 'id_rsa.pub' and click the 'Add key' button.

Sign up Restrictions

Click the 'Admin area' button on the middle, then click 'Settings'.
Uncheck the 'signup enabled' option and click the 'Save changes' button.

Account Limit

Click on the 'Account and limit' section and set the default project limit to 20.

And click the 'Save changes' button.

Step 8 - Testing Gitlab

Finally, we will do some tests to ensure that our GitLab system is working properly.

Create New Project


Click the plus icon on the top mid to create a new project repository. Type in your
project name, description, and set up the visibility settings of your project. Then
click on the 'Create project' button.

The new project has been created.

Test First Commit and Push

Now we will start adding new content to the repository. Make sure Git is installed on
your computer, and we need to set up the global username and email for git with
the command below.

git config global user.name "hakase"


git config global user.email "admin@hakase labs.io"

Clone the Repository and add a README.md file.

git clone https: git.hakase labs.pw/hakase/project01.git


cd project01/
vim README.md

You will be asked for the 'hakase' user password. Please type the same password
that you used when we accessed GitLab the first time.

Commit a new file to the 'project01' repository.


git add .
git commit m 'Add README.md file by hakase labs'

Next, push the change to the repository on the GitLab server.

git push origin master

Type in your password and press Enter to continue. You will see the result as below.

Now open the 'project01' project from your web browser, and you will see that the
new README.md file has been added to the repository.
GitLab installation guide on Ubuntu 18.04 has been completed successfully.

Reference
https://docs.gitlab.com/omnibus/

Você também pode gostar