Skip to content

部署 GitLab 私有服务器

GitLab 官方推荐在 Linux 系统上运行,但也可以在 Windows 上通过多种方式部署。以下是几种在 Windows 上部署 GitLab 的方法:

方法一:使用 Docker(推荐)

  1. 安装 Docker Desktop
  1. 运行 GitLab 容器
bash
docker run --detach \
--hostname gitlab.example.com \
--publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab \
--restart always \
--volume C:/GitLab/config:/etc/gitlab \
--volume C:/GitLab/logs:/var/log/gitlab \
--volume C:/GitLab/data:/var/opt/gitlab \
gitlab/gitlab-ee:latest
  1. 访问 GitLab
  • 首次启动可能需要几分钟初始化
  • 访问 http://localhost
  • 默认管理员用户名:root,初始密码在C:\GitLab\config\initial_root_password

方法二:使用虚拟机

  1. 安装 VirtualBox 或 Hyper-V
  2. 创建 Linux 虚拟机
  • 下载 Ubuntu Server ISO
  • 创建虚拟机并安装 Ubuntu
  1. 在虚拟机中安装 GitLab
bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl openssh-server ca-certificates postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo EXTERNAL_URL="http://gitlab.example.com" apt install gitlab-ee

方法三:使用 WSL 2(Windows Subsystem for Linux)

  1. 启用 WSL 2
powershell
wsl --install
wsl --set-default-version 2
  1. 安装 Ubuntu 发行版
  • 从 Microsoft Store 安装 Ubuntu
  1. 在 WSL 中安装 GitLab
bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl openssh-server ca-certificates postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo EXTERNAL_URL="http://localhost" apt install gitlab-ee

注意事项

  1. 性能考虑:Windows 上的 GitLab 性能可能不如原生 Linux 环境
  2. 资源需求:GitLab 需要至少 4GB RAM 和 2 核 CPU
  3. 备份:定期备份您的 GitLab 数据
  4. 更新:保持 GitLab 版本更新以获得安全修复和新功能
  5. 配置:根据需求调整gitlab.rb配置文件

替代方案

如果只是需要简单的 Git 服务,可以考虑:

  • Git for Windows 内置的简单 Git 服务器
  • Gitea - 更轻量级的 Git 服务,有 Windows 版本

希望这些信息对您有所帮助!根据您的具体需求选择最适合的部署方式。