温馨提示×

ubuntu gitlab怎么安装

小樊
44
2026-10-13 16:42:49
栏目: 智能运维

下面给你 在 Ubuntu 上安装 GitLab(社区版 CE) 的几种常见方式和步骤,最推荐的是 官方 Omnibus 包安装,简单稳定。


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

1. 更新系统

sudo apt update
sudo apt upgrade -y

2. 安装依赖

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

3. 添加 GitLab 官方仓库

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

4. 安装 GitLab CE

⚠️ 把 gitlab.example.com 改成你的域名或服务器 IP

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

如果是本地测试:

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

5. 访问 GitLab

浏览器打开:

http://你的IP或域名

首次登录账号:

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

二、安装后常用命令

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

三、使用 Docker 安装(可选,更轻量)

1. 安装 Docker

sudo apt install docker.io -y
sudo systemctl enable --now docker

2. 启动 GitLab 容器

sudo docker run -d \
  --hostname gitlab.example.com \
  -p 80:80 -p 443:443 -p 22:22 \
  --name gitlab \
  gitlab/gitlab-ce:latest

访问:

http://服务器IP

四、常见问题

1. 端口冲突(如 80 被占用)

修改:

sudo nano /etc/gitlab/gitlab.rb
external_url 'http://IP:8080'

然后:

sudo gitlab-ctl reconfigure

2. 内存不足

GitLab 至少 4G 内存,2G 容易卡死。

3. 配置 HTTPS

可使用 Let’s Encrypt:

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

五、总结推荐

场景 推荐方式
生产服务器 Omnibus
快速测试 Docker
云服务器 Omnibus + 域名

如果你告诉我:

  • Ubuntu 版本(20.04 / 22.04 / 24.04)
  • 是否用域名
  • 是否内网

我可以给你 更精确的命令。

0 踩