温馨提示×

GitLab如何集成CentOS

小樊
36
2026-07-20 03:55:57
栏目: 智能运维

在 GitLab 中集成 CentOS 通常指两种场景:
1️⃣ 在 CentOS 上安装 GitLab(GitLab 服务器运行在 CentOS)
2️⃣ GitLab CI/CD 集成 CentOS(作为构建/部署环境)

下面分别说明,你可以按需要选择。


一、在 CentOS 上安装 GitLab(最常见)

✅ 适用场景

  • 自建 GitLab 服务端
  • 使用 CentOS 7 / 8 / Stream

1️⃣ 系统准备

# 更新系统
sudo yum update -y

# 安装依赖
sudo yum install -y curl policycoreutils openssh-server perl

开启 SSH:

sudo systemctl enable sshd
sudo systemctl start sshd

2️⃣ 安装 GitLab 官方仓库

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

企业版(EE)可免费使用,也可用 gitlab-ce(社区版)


3️⃣ 安装 GitLab

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

✅ 如果你是本机测试:

sudo EXTERNAL_URL="http://localhost" yum install -y gitlab-ee

4️⃣ 初始化并启动

sudo gitlab-ctl reconfigure

访问:

http://服务器IP

首次登录会要求设置 root 密码


5️⃣ 常用管理命令

sudo gitlab-ctl status
sudo gitlab-ctl restart
sudo gitlab-ctl tail

二、GitLab CI/CD 集成 CentOS(Runner)

✅ 适用场景

  • GitLab 在别处(如 gitlab.com)
  • CentOS 作为构建/部署机器

1️⃣ 在 CentOS 上安装 GitLab Runner

curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
sudo yum install -y gitlab-runner

2️⃣ 注册 Runner

sudo gitlab-runner register

依次输入:

  • GitLab URL(如 https://gitlab.com
  • Registration Token(在 GitLab → Settings → CI/CD → Runners)
  • Runner 描述
  • Tags(如 centos
  • Executor(推荐 shelldocker

3️⃣ 启动 Runner

sudo gitlab-runner start

4️⃣ .gitlab-ci.yml 示例

stages:
  - build

build_on_centos:
  stage: build
  tags:
    - centos
  script:
    - cat /etc/centos-release
    - echo "Build on CentOS"

三、CentOS 集成 GitLab 常见问题

❓ CentOS 8 已停止维护怎么办?

✅ 推荐使用:

  • Rocky Linux
  • AlmaLinux
  • CentOS Stream 9

GitLab 官方仍支持这些系统。


❓ 防火墙问题

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

四、总结

集成方式 说明
GitLab 安装在 CentOS 自建 GitLab 服务器
GitLab Runner 在 CentOS CI/CD 构建/部署
Webhook + CentOS 自动化部署(较少用)

如果你能具体说明:

  • 是用 GitLab.com 还是自建?
  • CentOS 版本?
  • 想做 CI/CD 还是服务器部署?

我可以给你一套 完全贴合你环境的配置方案

0