如何在 Debian 11 上安装 GitLab
本教程适用于这些操作系统版本
- Debian 11(Bullseye)
- Debian 8(Jessie)
在此页
- 先决条件
- 开始
- 添加 GitLab 存储库
- 安装 GitLab CE
- 配置 GitLab
- 访问 GitLab
- 配置 GitLab 备份
- 结论
GitLab 是一个免费的开源 DevOps 平台,可让团队更快地迭代并共同创新。它是由 GitLab Inc 开发的基于 Web 的工具。它与 GitHub 非常相似,提供了一个 Git 存储库管理器,提供 wiki、问题跟踪以及持续集成和部署。 GitLab 社区版可完全免费用于开发和生产环境。
在本教程中,我将向您展示如何在 Debian 11 上使用 Nginx 安装 GitLab 并让我们加密 SSL。
先决条件
- 一台运行 Debian 11 且内存至少为 8GB 的服务器。
- 用服务器 IP 指向的有效域名。
- 在服务器上配置了根密码。
入门
在开始之前,建议将您的包缓存更新到最新版本。您可以使用以下命令执行此操作:
apt-get update -y
完成后,使用以下命令安装其他所需的依赖项:
apt-get install curl ca-certificates apt-transport-https gnupg2 -y
安装所有必需的依赖项后,您可以继续下一步。
添加 GitLab 存储库
默认情况下,GitLab 包在 Debian 默认存储库中不可用。因此,您需要将 GitLab 存储库添加到 APT。
您可以通过运行以下脚本来添加它:
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash
这会将 GitLab 存储库添加到 APT 源列表文件中。
在撰写本文时,GitLab 软件包不适用于 Debian 11。因此您需要编辑 GitLab 源文件并将 Debian 11 代号替换为 Debian 10:
nano /etc/apt/sources.list.d/gitlab_gitlab-ce.list
找到以下几行:
deb https://packages.gitlab.com/gitlab/gitlab-ce/debian/ bullseye main
deb-src https://packages.gitlab.com/gitlab/gitlab-ce/debian/ bullseye main
将它们替换为以下行:
deb https://packages.gitlab.com/gitlab/gitlab-ce/debian/ buster main
deb-src https://packages.gitlab.com/gitlab/gitlab-ce/debian/ buster main
保存并关闭文件,然后使用以下命令更新存储库:
apt-get update -y
安装 GitLab CE
您现在可以通过运行以下命令来安装 GitLab CE:
apt-get install gitlab-ce -y
安装 GitLab 后,您应该获得以下输出:
It looks like GitLab has not been configured yet; skipping the upgrade script.
*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=14-3
配置 GitLab
此时,GitLab 已安装在您的系统上,但尚未配置。您可以通过编辑以下文件来配置它:
nano /etc/gitlab/gitlab.rb
使用您的域名更改以下行:
external_url 'https://gitlab.linuxbuz.com'
接下来,更改以下行以启用 Lets Encrypt SSL:
# Enable the Let's encrypt SSL
letsencrypt['enable'] = true
# This is optional to get SSL related alerts
letsencrypt['contact_emails'] = ['']
# This example renews every 7th day at 02:00 AM
letsencrypt['auto_renew_hour'] = "2"
letsencrypt['auto_renew_minute'] = "0"
letsencrypt['auto_renew_day_of_month'] = "*/7"
保存并关闭文件,然后使用以下命令重新配置 GitLab:
gitlab-ctl reconfigure
重新配置 GitLab 后,您应该获得以下包含 GitLab 访问密码的输出:
Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.
NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
gitlab Reconfigured!
接下来,使用以下命令检索 GitLab 访问密码:
cat /etc/gitlab/initial_root_password
您应该看到以下输出:
# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: WBgnk2SH4xK5FeJVsJX0Qo79IeyE5LSTGWm3EjDVEkw=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
访问 GitLab
您现在可以使用 URL https://gitlab.linuxbuz.com 访问 GitLab 仪表板。您将被重定向到 GitLab 登录页面:

提供您的用户名、密码,然后单击“登录”按钮。您应该会在以下屏幕上看到 GitLab 仪表板:

配置 GitLab 备份
安装完成后,建议对 GitLab 进行完整备份。您可以使用以下命令执行此操作:
gitlab-rake gitlab:backup:create
您还可以通过编辑 /etc/crontab 文件来安排备份:
nano /etc/crontab
添加以下行:
0 22 * * * root gitlab-rake gitlab:backup:create
完成后保存并关闭文件。
结论
恭喜!您已经在 Debian 11 上成功安装了带有 Nginx 和 Lets Encrypt SSL 的 GitLab。您现在可以在开发环境中实施 GitLab 以加快软件开发过程。如果您有任何问题,请随时问我。