ZH ·
🌏 English

在 Ubuntu 16.04 局域网环境下搭建 GitLab 服务

GitLab 的功能与 GitHub 一样强大。我们决定将版本控制系统从 SVN 迁移到 Git,并在局域网内运行 GitLab 服务器。由于市面上关于 GitLab 安装的教程往往过于冗长且复杂,且大多针对拥有域名的环境,因此我编写了这篇指南,专注于在局域网内快速部署 GitLab。

在安装 GitLab 之前,请先更新 Ubuntu 软件包仓库:

sudo apt-get update

安装前置依赖软件包:

sudo apt install curl openssh-server ca-certificates postfix

在 Postfix 安装过程中,选择“Internet Site”,并输入用于发送邮件的服务器域名。如果你没有域名,随意输入一个名称即可。

使用 curl 命令添加 GitLab 仓库:

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

这一步非常关键。我认为这是安装 GitLab 最好的方法之一,因为添加仓库后,我们可以通过简单的命令直接安装 GitLab 软件包:

sudo apt install gitlab-ce

接下来,更新配置文件:

sudo vim /etc/gitlab/gitlab.rb

由于我们没有为 GitLab 服务器配置域名,我们将使用服务器的 IP 地址,并继续使用 http 协议:

external_url 'http://your_ipaddress'

然后运行重新配置命令:

sudo gitlab-ctl reconfigure

配置完成。

对于像我这样只想在局域网内使用 GitLab 的用户,安装到此就结束了。如果你拥有域名并希望为 GitLab 启用 HTTPS 协议,则需要进行额外的配置。现在,你已经可以通过局域网内的 IP 地址访问 GitLab 了。

502 Whoops, GitLab is taking too much time to respond.

如果访问 GitLab 时一直出现“502 Whoops, GitLab is taking too much time to respond.”错误,你需要检查服务器端口。在我的案例中,服务器上运行的另一个服务占用了 8080 端口,而这正是 GitLab 中 Puma 服务所需要的。你需要在 /etc/gitlab/gitlab.rb 中修改 Puma 端口并重新配置:

puma['port'] = some_port_here

这对我有效,希望对你也有帮助。

参考资料

how-to-install-and-configure-gitlab-on-ubuntu-16-04 [digitalocean]

how-to-install-and-configure-gitlab-on-ubuntu-16-04 [howtoforge]

502-whoops-gitlab-is-taking-too-much-time-to-respond