温馨提示×

linux下怎样装gitlab

小樊
39
2026-10-07 08:58:04
栏目: 智能运维

在 Linux 下安装 GitLab,常见有两种方式:Omnibus 包安装(官方推荐) 和 Docker 安装。下面分别说明,最常用的是 Ubuntu / CentOS + Omnibus。


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

1️⃣ 准备工作

  • 一台 Linux 服务器(推荐 4G+ 内存)
  • 系统示例:
    • Ubuntu 20.04 / 22.04
    • CentOS 7 / 8

2️⃣ Ubuntu 安装 GitLab

(1)安装依赖

sudo apt update
sudo apt install -y curl openssh-server ca-certificates postfix

postfix 用于邮件,可选

(2)添加 GitLab 源

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

(3)安装 GitLab

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

如果是本地测试:

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

(4)访问

浏览器打开:

http://服务器IP

首次登录账号:root 密码在:

cat /etc/gitlab/initial_root_password

3️⃣ CentOS 安装 GitLab

sudo yum install -y curl policycoreutils openssh-server postfix
sudo systemctl enable sshd postfix
sudo systemctl start sshd postfix

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

sudo EXTERNAL_URL="http://服务器IP" yum install gitlab-ee

二、使用 Docker 安装(更简单)

1️⃣ 安装 Docker

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

2️⃣ 启动 GitLab

docker run -d \
  --hostname gitlab.example.com \
  -p 443:443 -p 80:80 -p 22:22 \
  --name gitlab \
  --restart always \
  -v /srv/gitlab/config:/etc/gitlab \
  -v /srv/gitlab/logs:/var/log/gitlab \
  -v /srv/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ee:latest

访问:

http://服务器IP

三、常用管理命令

sudo gitlab-ctl reconfigure   # 重新加载配置
sudo gitlab-ctl restart       # 重启
sudo gitlab-ctl status        # 查看状态

四、常见问题

❓ 内存不足

GitLab 至少 4G,否则容易 502

❓ 修改访问地址

vi /etc/gitlab/gitlab.rb

修改:

external_url 'http://新地址'

然后:

gitlab-ctl reconfigure

如果你告诉我:

  • 系统版本(Ubuntu / CentOS / Debian)
  • 是否用 Docker
  • 是否内网 / 公网

我可以给你精确的一步一步命令。

0 踩