本教程适用于以下操作系统版本
- Debian 11 (Bullseye)
- Debian 8 (Jessie)
本页内容
- 先决条件
- 入门
- 添加 GitLab 仓库
- 安装 GitLab CE
- 配置 GitLab
- 访问 GitLab
- 配置 GitLab 备份
- 结论
GitLab 是一个免费的开源 DevOps 平台,可让团队更快地迭代并共同创新。它是由 GitLab Inc. 开发的基于 Web 的工具。它与 GitHub 非常相似,提供了一个 Git 仓库管理器,提供 wiki、问题跟踪以及持续集成和部署。GitLab 社区版对于开发和生产环境完全免费。
在本教程中,我将向您展示如何在 Debian 11 上使用 Nginx 和 Let's Encrypt SSL 安装 GitLab。
先决条件
- 一台运行 Debian 11 且内存至少 8GB 的服务器。
- 一个指向服务器 IP 的有效域名。
- 服务器上已配置 root 密码。
入门
在开始之前,建议将软件包缓存更新到最新版本。您可以使用以下命令来完成:
apt-get update -y
完成后,使用以下命令安装其他所需的依赖项:
apt-get install curl ca-certificates apt-transport-https gnupg2 -y
一旦所有必需的依赖项都安装完毕,您就可以继续下一步。
添加 GitLab 仓库
默认情况下,Debian 默认仓库中没有 GitLab 软件包。因此您需要将 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'
接下来,更改以下几行以启用 Let's Encrypt SSL:
# Enable the Let's encrypt SSL letsencrypt['enable'] = true # This is optional to get SSL related alerts letsencrypt['contact_emails'] = [' [email protected] '] # 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 和 Let's Encrypt SSL 成功安装了 GitLab。您现在可以在开发环境中实施 GitLab,以加快软件开发过程。如有任何问题,请随时问我。