温馨提示×

怎样在linux配gitlab

小樊
40
2026-09-25 17:55:59
栏目: 智能运维

下面按常见场景给你讲怎么在 Linux 上“配 GitLab”。先确认你是哪一种需求:

  1. 在 Linux 上部署 GitLab 服务(自建 GitLab)
  2. 在 Linux 上使用 GitLab(客户端:clone / push / SSH / Token)
  3. Linux 上配置 GitLab Runner(CI/CD)

我分别说,你可以按需看。


一、在 Linux 上部署 GitLab(最常见)

1️⃣ 系统要求

  • 推荐:Ubuntu / CentOS / Debian
  • 内存:至少 4GB(8GB 更稳)
  • 用户:root 或 sudo 权限

2️⃣ Ubuntu 安装 GitLab(CE 社区版)

# 安装依赖
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="http://gitlab.example.com" apt install gitlab-ee

如果是 CE:

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo EXTERNAL_URL="http://gitlab.example.com" apt install gitlab-ce

3️⃣ 初始化配置

sudo gitlab-ctl reconfigure

访问:

http://服务器IP

首次登录:

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

4️⃣ 常用管理命令

sudo gitlab-ctl start
sudo gitlab-ctl stop
sudo gitlab-ctl restart
sudo gitlab-ctl status

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

1️⃣ 安装 git

sudo apt install git     # Ubuntu
sudo yum install git     # CentOS

2️⃣ 配置用户

git config --global user.name "yourname"
git config --global user.email "you@example.com"

3️⃣ SSH 方式(推荐)

ssh-keygen -t ed25519 -C "you@example.com"
cat ~/.ssh/id_ed25519.pub

复制到:

GitLab → Settings → SSH Keys

测试:

ssh -T git@gitlab.com

4️⃣ HTTPS + Token(不用密码)

GitLab → Access Tokens → 创建 token

git clone https://gitlab.com/username/repo.git
# 用户名:yourname
# 密码:token

三、配置 GitLab Runner(CI/CD)

# 安装
sudo apt install gitlab-runner

# 注册
sudo gitlab-runner register

按提示填:

  • GitLab URL
  • Token(项目 / 管理员页面)
  • executor:shell 或 docker

四、常见问题

✅ 端口冲突(80/443)

sudo vim /etc/gitlab/gitlab.rb
external_url 'http://ip:8080'
sudo gitlab-ctl reconfigure

✅ 内存不足

  • 关掉 unused services
  • 或换 Gitea

五、你可以告诉我

  • 你是 Ubuntu 还是 CentOS?
  • 是想 搭服务 还是 只连 GitLab?
  • 是否有 域名 / 公网 IP?

我可以直接给你一套可执行命令。

0 踩