温馨提示×

怎样在Debian部署GitLab

小樊
34
2026-08-28 17:34:14
栏目: 智能运维

下面给你一份**在 Debian 上部署 GitLab(Community Edition,CE)**的完整、常用实践方案,适用于 Debian 11/12
如果你只是想快速跑起来,用 Omnibus 包是最省事的。


一、准备条件

1️⃣ 服务器要求

项目 建议
CPU 2 核及以上
内存 至少 4GB(8GB 更佳)
磁盘 20GB+(视仓库大小)
系统 Debian 11 (Bullseye) / 12 (Bookworm)
网络 固定 IP 或域名

⚠️ GitLab 比较吃内存,低于 4GB 不建议生产使用


二、安装依赖

sudo apt update
sudo apt install -y \
  curl \
  openssh-server \
  ca-certificates \
  tzdata \
  gnupg

三、添加 GitLab 官方仓库(推荐)

1️⃣ 添加 GPG 密钥

curl -fsSL https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey | \
  sudo gpg --dearmor -o /usr/share/keyrings/gitlab-ce.gpg

2️⃣ 添加 APT 源

echo "deb [signed-by=/usr/share/keyrings/gitlab-ce.gpg] \
https://packages.gitlab.com/gitlab/gitlab-ce/debian $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/gitlab-ce.list

四、安装 GitLab CE

sudo apt update
sudo apt install -y gitlab-ce

安装完成后会看到类似提示:

Thank you for installing GitLab!

五、基础配置

1️⃣ 编辑配置文件

sudo vim /etc/gitlab/gitlab.rb

必须改的配置

external_url 'http://gitlab.example.com'

✅ 改成你的:

  • 域名:http://git.example.com
  • 或 IP:http://192.168.1.100

2️⃣ 如果要用 HTTPS(可选)

external_url 'https://gitlab.example.com'

GitLab 会自动申请 Let’s Encrypt 证书(需 80/443 端口开放)。


3️⃣ 应用配置

sudo gitlab-ctl reconfigure

该过程会:

  • 生成配置
  • 启动所有服务
  • 初始化数据库

⏳ 通常需要 2–5 分钟


六、访问 GitLab

浏览器访问:

http://你的IP或域名

首次登录:

  • 用户名:root
  • 密码查看方式:
sudo cat /etc/gitlab/initial_root_password

⚠️ 密码 24 小时后自动删除,首次登录请立即修改。


七、常用管理命令

# 查看状态
sudo gitlab-ctl status

# 重启
sudo gitlab-ctl restart

# 查看日志
sudo gitlab-ctl tail

# 停止
sudo gitlab-ctl stop

八、中文界面设置

  1. 登录 GitLab
  2. 右上角头像 → Preferences
  3. Localization → Language → 简体中文
  4. 保存并刷新

九、生产环境建议(重要)

必须

  • 使用域名 + HTTPS
  • 定期备份
sudo gitlab-backup create

推荐

  • 单独服务器,不混用其他服务
  • 配置 SMTP 邮件
  • 配置防火墙(只开放 22 / 80 / 443)

十、常见问题

❓ 内存不足

# 减少 Sidekiq / Puma 进程
sudo vim /etc/gitlab/gitlab.rb
puma['worker_processes'] = 2
sidekiq['max_concurrency'] = 10
sudo gitlab-ctl reconfigure

❓ 端口冲突

GitLab 默认用 80 / 443 / 22
可改为其他端口:

nginx['listen_port'] = 8080

十一、可选替代方案

需求 建议
简单、快速 官方 Omnibus
Kubernetes GitLab Helm Chart
轻量 Gitea(非 GitLab)

如果你愿意,我可以帮你:

  • ✅ 配置 HTTPS + 自动证书
  • ✅ 配置 SMTP 邮箱
  • ✅ 做 生产级优化
  • ✅ 写 Ansible / 一键脚本

只要告诉我你的 Debian 版本 + 使用场景 即可。

0