Deploy GitLab In Ubuntu Server

GitLab is a web-based Git-repository manager providing wiki, issue-tracking and CI/CD pipeline features, using an open-source license, developed by GitLab Inc.
                                        —— Wikipedia

Preparation

Opreating System

If the system of your server is Ubunntu-16.04LTS, and the machine hasn't powerful hardware resources, such RAM, I'll suggest update system to Ubuntu-18.04LTS by conmand lines instead of re-installing.

Keep your Ubuntu-16.04LTS is newest.

1
2
3
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get dist-upgrade

Start to update system, and make your selection carefully based on the following tips.

1
$ sudo do-release-upgrade

Dependencies

Install and configure dependencies.

1
2
$ sudo apt-get update                                           # 刷新本地包索引
$ sudo apt-get install -y curl openssh-server ca-certificates # 安装必要依赖

IP & DNS

Look out Public IP or DNS.

1
2
3
$ curl ifconfig.me                                  # 查看公网IP
XXX.96.XXX.132
$ cat /etc/resolv.conf | grep 'nameserver' # 查看DNS

Notification Emails

Install Postfix for notifcation emails.

1
$ sudo apt-get install -y postfix                   # 安装postfix发送通知邮件,可跳过

Choose InternetSite, and type DNS of your server.

Change Sources

Change Sources for a faster speed to download.

1
2
3
$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak       # 备份旧源 
$ sudo rm /etc/apt/sources.list # 移除旧源
$ sudo vim /etc/apt/sources.list # 编辑新源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# /etc/apt/sources.list
# from aliyun_sources
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
1
$ sudo apt-get update                               # 更新源

Add & Install

Repository

Add GitLab package repository.

1
$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash  # 添加 GitLab 包仓库

GitLab-ee

Install GitLab package.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ sudo EXTERNAL_URL="http://XXX.96.XXX.132" apt-get install gitlab-ee                            # 安装GitLab包
... ... ...
Chef Client finished, 453/670 resources updated in 01 minutes 57 seconds
gitlab Reconfigured!

*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.



_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/


Thank you for installing GitLab!
GitLab should be available at http://XXX.96.XXX.132
... ... ...

Configure

Potocol & Port

Customize Firewall Settings or Security Group Configuration at the server vendor if necessary.
译:必要的话在 服务器供应商(如 阿里云) 处自定义 防火墙设置安全组配置

IP & DNS

Add Public IP or DNS for GitLab server.

1
$ sudo vim /etc/gitlab/gitlab.rb        # 配置 server IP 或 DNS
1
2
3
4
# /etc/gitlab/gitlab.rb
... ...
external_url 'http://XXX.96.XXX.132:443' # 修改 external_url
... ...

Firewall

Show Firewall status.

1
2
3
$ su root
# ufw status # 显示防火墙状态
Status: inactive

Make Firewall active.

1
2
3
# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup

Add allowed protocol.

1
2
3
# ufw allow ssh                         # 允许 ssh 访问
# ufw allow http # 允许 http 访问
# ufw allow https # 允许 https 访问

Show Firewall status again.

1
2
3
4
5
6
7
8
9
10
11
# ufw status
Status: active

To Action From
-- ------ ----
22 ALLOW Anywhere
80 ALLOW Anywhere
443 ALLOW Anywhere
22 (v6) ALLOW Anywhere (v6)
80 (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)

Browse

Initial configuration by browse http://XXX.96.XXX.132:443
What's up! !

You need to reconfigure and restart after modify configuration of GitLab. (The default is that service of GitLab will run after boot every time, but you can use 'gitlab-ctl stop' to stop it.)

1
2
# gitlab-ctl reconfigure
# gitlab-ctl restart

Show GitLab Status if necessary.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ gitlab-ctl status
run: alertmanager: (pid 1234) 1434s; run: log: (pid 1225) 1434s
run: gitaly: (pid 1231) 1434s; run: log: (pid 1223) 1434s
run: gitlab-monitor: (pid 1235) 1434s; run: log: (pid 1230) 1434s
run: gitlab-workhorse: (pid 1236) 1434s; run: log: (pid 1222) 1434s
run: logrotate: (pid 1241) 1434s; run: log: (pid 1217) 1434s
run: nginx: (pid 1232) 1434s; run: log: (pid 1219) 1434s
run: node-exporter: (pid 1239) 1434s; run: log: (pid 1226) 1434s
run: postgres-exporter: (pid 1240) 1434s; run: log: (pid 1221) 1434s
run: postgresql: (pid 1245) 1434s; run: log: (pid 1224) 1434s
run: prometheus: (pid 1237) 1434s; run: log: (pid 1220) 1434s
run: redis: (pid 1238) 1434s; run: log: (pid 1229) 1434s
run: redis-exporter: (pid 1253) 1434s; run: log: (pid 1246) 1434s
run: sidekiq: (pid 3609) 15s; run: log: (pid 1228) 1434s
run: unicorn: (pid 3470) 78s; run: log: (pid 1227) 1434s

Browse http://XXX.96.XXX.132:443 again.
Things have improved.

Refresh web page multiple times until everything is good.
Nice!

Manage

Log in as root.

Start manage you GitLab server.


Unfinished