温馨提示×

gitlab linux怎么设置

小樊
35
2026-09-19 14:54:49
栏目: 智能运维

你这个问题比较宽泛,我先分几种最常见的 GitLab 在 Linux 上的使用场景来说明,你可以看哪一种符合你的需求:


一、在 Linux 上安装 GitLab(自建 GitLab 服务)

1️⃣ 系统要求

  • 推荐:Ubuntu / CentOS / Debian
  • 内存:至少 4GB(2GB 会很卡)
  • 用户:root 或具有 sudo 权限

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

# 更新系统
sudo apt update && sudo apt upgrade -y

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

# 添加 GitLab 源
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

# 安装 GitLab(替换成你的域名或 IP)
sudo EXTERNAL_URL="http://gitlab.example.com" apt install gitlab-ce

安装完成后:

sudo gitlab-ctl reconfigure

访问:

http://服务器IP

默认账号:

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

3️⃣ CentOS / Rocky / AlmaLinux

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

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

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

二、在 Linux 上使用 GitLab(作为客户端)

1️⃣ 安装 Git

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

2️⃣ 配置 Git

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

3️⃣ 配置 SSH 密钥(推荐)

ssh-keygen -t rsa -b 4096 -C "你的邮箱"
cat ~/.ssh/id_rsa.pub

把内容复制到: GitLab → Settings → SSH Keys


三、GitLab Runner(Linux 上跑 CI/CD)

# 安装
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
sudo apt install gitlab-runner

# 注册
sudo gitlab-runner register

需要填写:

  • GitLab 地址
  • Token(项目或组里获取)
  • 执行器(shell / docker)

四、常见问题

✅ 端口冲突(80/443)
✅ 内存不足导致 502
✅ 防火墙未开放

sudo ufw allow 80
sudo ufw allow 443

你可以告诉我:

1️⃣ 你是 安装 GitLab 服务 还是 使用 GitLab
2️⃣ 用的 什么 Linux 发行版
3️⃣ 是 服务器还是本地虚拟机

我可以直接给你一套适合你环境的完整命令

0