温馨提示×

linux上怎样装gitlab

小樊
48
2026-10-22 00:17:28
栏目: 智能运维

在 Linux 上安装 GitLab 通常有两种主流方式:

  1. Omnibus 包安装(官方推荐,最简单)
  2. Docker 安装(更灵活,适合已有 Docker 环境)

下面分别说明,以 Ubuntu / Debian 和 CentOS / RHEL 为例。


一、使用官方 Omnibus 包安装(推荐)

1️⃣ Ubuntu / Debian

# 安装依赖
sudo apt update
sudo apt install -y curl openssh-server ca-certificates tzdata perl

# 添加 GitLab 仓库
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash

# 安装 GitLab(替换为你自己的域名)
sudo EXTERNAL_URL="https://gitlab.example.com" apt install gitlab-ee

如果是社区版,把 gitlab-ee 换成 gitlab-ce


2️⃣ CentOS / RHEL

# 安装依赖
sudo yum install -y curl policycoreutils openssh-server perl

# 添加 GitLab 仓库
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

# 安装 GitLab
sudo EXTERNAL_URL="https://gitlab.example.com" yum install gitlab-ee

3️⃣ 安装后配置

sudo gitlab-ctl reconfigure

访问:

http://<服务器IP>

默认用户名:root 密码在:

sudo cat /etc/gitlab/initial_root_password

二、使用 Docker 安装(更轻量)

1️⃣ 安装 Docker

curl -fsSL https://get.docker.com | bash
sudo systemctl enable --now docker

2️⃣ 启动 GitLab 容器

sudo docker run --detach \
  --hostname gitlab.example.com \
  --publish 443:443 --publish 80:80 --publish 22:22 \
  --name gitlab \
  --restart always \
  --volume /srv/gitlab/config:/etc/gitlab \
  --volume /srv/gitlab/logs:/var/log/gitlab \
  --volume /srv/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ee:latest

访问:

http://<服务器IP>

三、常见问题

✅ 端口冲突(80 / 22 被占用)

修改 /etc/gitlab/gitlab.rb:

external_url 'http://gitlab.example.com'
nginx['listen_port'] = 8080

然后:

sudo gitlab-ctl reconfigure

✅ 修改 root 密码

sudo gitlab-rake "gitlab:password:reset[root]"

✅ 查看服务状态

sudo gitlab-ctl status

四、选择建议

场景 推荐方式
新手 / 生产环境 Omnibus
已有 Docker Docker
测试 / 快速体验 Docker

如果你愿意,可以告诉我:

  • 你用的是 哪种 Linux
  • 是 学习 / 公司内网 / 公网
  • 是否需要 HTTPS / 域名

我可以直接给你一套完整配置。

0 踩