温馨提示×

如何在Debian配置GitLab

小樊
39
2026-08-02 08:47:18
栏目: 智能运维

在Debian系统上配置 GitLab,通常推荐使用 官方 Omnibus 包,因为它集成了所有依赖,安装和配置相对简单。以下是详细步骤:


一、准备环境

1. 系统要求

  • Debian 10 (Buster) / 11 (Bullseye) / 12 (Bookworm)
  • 至少 4GB 内存(GitLab 比较吃内存)
  • 已配置好域名(如 gitlab.example.com,可选但推荐)

2. 更新系统

sudo apt update
sudo apt upgrade -y

二、安装依赖

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

如果需要邮件通知,可安装 Postfix:

sudo apt install -y postfix

选择 Internet Site,并设置域名。


三、添加 GitLab 官方仓库

1. 下载并运行安装脚本

curl -fsSL https://packages.gitlab.com/setup.sh | sudo bash

该脚本会自动添加 GitLab CE 的 APT 源。


四、安装 GitLab CE

1. 设置访问地址并安装

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

✅ 如果暂时没有域名,可先用 IP:

sudo EXTERNAL_URL="http://你的服务器IP" apt install gitlab-ce

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

Thank you for installing GitLab!

五、初始化配置

1. 重新配置 GitLab

sudo gitlab-ctl reconfigure

⚠️ 首次执行时间较长,请耐心等待。


六、访问 GitLab

  1. 打开浏览器访问:

    http://gitlab.example.com
    

    http://服务器IP
    
  2. 首次访问会要求设置 管理员密码

    • 默认用户名:root
    • 密码在首次设置后生效

七、常用配置(可选)

1. 修改外部访问地址

编辑配置文件:

sudo nano /etc/gitlab/gitlab.rb

修改:

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

然后执行:

sudo gitlab-ctl reconfigure

2. 开启 HTTPS(推荐)

使用 Let’s Encrypt

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

letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true

然后:

sudo gitlab-ctl reconfigure

3. 查看服务状态

sudo gitlab-ctl status

4. 重启 GitLab

sudo gitlab-ctl restart

八、常见问题

1. 内存不足

  • 建议至少 4GB
  • 可关闭部分服务(CI Runner、监控)

2. 访问慢

  • 检查 DNS
  • 关闭或限制 Prometheus

3. 端口冲突

GitLab 默认使用:

  • 80 / 443(Web)
  • 22(SSH)

九、卸载 GitLab(如需)

sudo gitlab-ctl uninstall
sudo apt remove gitlab-ce -y
sudo apt purge gitlab-ce -y

如果你需要:

  • GitLab EE(企业版)
  • Docker 方式部署
  • 与 Nginx / Apache 共存
  • CI/CD Runner 配置
  • 备份与迁移

可以告诉我你的具体需求,我可以给你更精确的方案。

0