温馨提示×

GitLab如何在Debian运行

小樊
41
2026-08-28 18:25:14
栏目: 智能运维

Debian 上运行 GitLab,推荐并且官方支持的方式是使用 Omnibus GitLab 软件包。下面我按 最常见、最稳妥 的方式一步步说明。


一、推荐方案:使用 Omnibus GitLab(官方)

✅ 适用场景

  • 生产环境
  • 快速部署
  • 不想手动维护组件(Nginx、PostgreSQL、Redis 等)

二、准备环境

1️⃣ 系统要求

  • Debian 10 / 11 / 12(推荐 Debian 11 Bullseye
  • 最低配置:
    • CPU:2 核
    • 内存:至少 4GB(8GB 更佳)
    • 磁盘:20GB+

2️⃣ 更新系统

sudo apt update
sudo apt upgrade -y

三、安装依赖

sudo apt install -y curl openssh-server ca-certificates tzdata

四、添加 GitLab 官方仓库

1️⃣ 下载并运行官方安装脚本

curl -fsSL https://packages.gitlab.com/gitlab/gitlab-ee/script.deb.sh | sudo bash

如果你用的是 CE(社区版),把 gitlab-ee 改成 gitlab-ce


五、安装 GitLab

1️⃣ 设置访问地址

sudo EXTERNAL_URL="http://gitlab.example.com" apt install gitlab-ee

✅ 本地测试可直接用:

sudo EXTERNAL_URL="http://localhost" apt install gitlab-ee

⚠️ 如果是服务器,建议用 域名或公网 IP


六、初始化配置

1️⃣ 重配置 GitLab

sudo gitlab-ctl reconfigure

这一步会:

  • 自动配置 Nginx
  • 初始化数据库
  • 启动所有服务

七、访问 GitLab

浏览器访问:

http://服务器IP

首次登录:

  • 用户名:root
  • 密码在:
sudo cat /etc/gitlab/initial_root_password

⚠️ 密码只在 24 小时内可见


八、常用管理命令

sudo gitlab-ctl status        # 查看状态
sudo gitlab-ctl stop          # 停止
sudo gitlab-ctl start         # 启动
sudo gitlab-ctl restart       # 重启
sudo gitlab-ctl tail          # 查看日志

九、配置文件位置

主配置文件:

/etc/gitlab/gitlab.rb

修改后记得:

sudo gitlab-ctl reconfigure

十、可选配置

✅ 修改端口

external_url 'http://your-ip:8080'
nginx['listen_port'] = 8080

✅ 使用 HTTPS(推荐)

sudo apt install certbot
sudo gitlab-ctl renew-le-certs

十一、资源占用提醒(很重要)

GitLab 非常吃资源

  • 内存建议 ≥ 8GB
  • 4GB 内存下建议关闭部分服务(CI Runner、Elasticsearch 等)

十二、不推荐方案(了解即可)

方式 说明
Docker 官方也支持,但 Debian 上运维更复杂
源码安装 非常复杂,不适合生产
手动组件 容易踩坑

十三、常见问题

❓ 页面打不开?

sudo gitlab-ctl status
sudo gitlab-ctl tail nginx

❓ 502 错误?

  • 内存不足
  • 配置未 reconfigure

十四、总结一句话

在 Debian 上运行 GitLab,最稳妥的方式就是:
用官方 Omnibus 包 + 足够内存 + 正确配置 external_url


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

  • ✅ 给你 一步一步的实战命令
  • ✅ 帮你 配置 HTTPS + 域名
  • ✅ 给你 低内存优化方案
  • ✅ 对比 GitLab vs Gitea vs Forgejo

你现在是 本地测试 还是 服务器部署

0