温馨提示×

如何在ubuntu配gitlab

小樊
48
2026-10-10 17:48:23
栏目: 智能运维

在 Ubuntu 上“配 GitLab”通常有两种常见含义,我先帮你区分一下,然后分别说明:


一、在 Ubuntu 上安装并搭建 GitLab 服务(自建 GitLab)

适合:你想自己有一台 GitLab 服务器

1️⃣ 系统要求

  • Ubuntu 20.04 / 22.04(推荐)
  • 至少 4 GB 内存(2 GB 会很卡)
  • 有 sudo 权限

2️⃣ 安装依赖

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

3️⃣ 添加 GitLab 仓库

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

4️⃣ 安装 GitLab

sudo EXTERNAL_URL="http://你的IP或域名" apt install gitlab-ee

例如:

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

5️⃣ 初始化并启动

sudo gitlab-ctl reconfigure

6️⃣ 访问 GitLab

浏览器打开:

http://你的IP

默认管理员:

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

二、在 Ubuntu 上使用 GitLab(客户端配置)

适合:你只是要用 GitLab(拉代码、推代码)

1️⃣ 安装 Git

sudo apt update
sudo apt install git

2️⃣ 配置用户信息

git config --global user.name "你的名字"
git config --global user.email "你的邮箱"

3️⃣ 生成 SSH Key

ssh-keygen -t ed25519 -C "你的邮箱"

查看公钥:

cat ~/.ssh/id_ed25519.pub

复制到 GitLab: User → Preferences → SSH Keys

4️⃣ 克隆仓库

git clone git@gitlab.com:用户名/项目.git

三、常见问题

❓ GitLab 很占内存?

可关闭部分服务:

sudo gitlab-ctl stop prometheus
sudo gitlab-ctl stop grafana

❓ 想用 Docker 装?

docker run --detach \
  --hostname gitlab.example.com \
  --publish 443:443 --publish 80:80 \
  --name gitlab \
  gitlab/gitlab-ee

如果你能告诉我:

  • ✅ 是搭服务器还是用 GitLab
  • ✅ Ubuntu 版本
  • ✅ 是否用 Docker / 云服务器

我可以直接给你一步一步可复制的命令。

0 踩