温馨提示×

gitlab在debian如何部署

小樊
51
2026-09-08 12:06:27
栏目: 智能运维

下面给你一份**在 Debian 上部署 GitLab(社区版 CE)**的常用、可靠方案,适合自建服务器或云主机。


一、环境准备

1. 系统要求

  • Debian 11(Bullseye)或 Debian 12(Bookworm)
  • 至少 4GB 内存(2GB 容易卡)
  • 磁盘空间 ≥ 20GB

2. 更新系统

sudo apt update
sudo apt upgrade -y

二、安装依赖

sudo apt install -y curl openssh-server ca-certificates postfix
  • postfix:用于邮件通知
  • 若不想用邮件,可选择 No configuration

三、添加 GitLab 官方源

方式一(推荐):使用官方脚本

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

四、安装 GitLab CE

1. 设置访问地址

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

如果是 IP 访问:

sudo EXTERNAL_URL="http://192.168.1.100" apt install gitlab-ce

2. 等待安装完成

安装完成后会自动执行 gitlab-ctl reconfigure


五、基础配置

1. 修改配置(可选)

sudo vim /etc/gitlab/gitlab.rb

常见修改:

external_url 'http://gitlab.example.com'
gitlab_rails['gitlab_shell_ssh_port'] = 22

2. 重新加载配置

sudo gitlab-ctl reconfigure

六、访问 GitLab

浏览器访问:

http://服务器IP

首次登录:

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

七、常用管理命令

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

八、防火墙(如有)

sudo ufw allow 80
sudo ufw allow 22

九、可选优化

1. 使用 HTTPS(推荐)

external_url 'https://gitlab.example.com'
letsencrypt['enable'] = true

2. 关闭不需要的服务(低配机器)

prometheus_monitoring['enable'] = false

十、常见问题

1. 页面打不开

  • 检查 gitlab-ctl status
  • 查看 sudo gitlab-ctl tail nginx

2. 内存不足

  • 最低 4GB
  • 关闭 Prometheus / Grafana

如果你需要:

  • Docker 部署 GitLab
  • GitLab + HTTPS + 域名
  • GitLab Runner(CI/CD)
  • 国内加速源

告诉我你的使用场景,我可以给你更具体的方案。

0