centos

如何在 CentOS 上安装 GitLab CI

小樊
48
2025-08-20 17:10:38
栏目: 智能运维

在 CentOS 上安装 GitLab CI 需要几个步骤。以下是一个基本的指南:

1. 更新系统

首先,确保你的 CentOS 系统是最新的。

sudo yum update -y

2. 安装必要的依赖包

安装一些必要的依赖包,这些包将帮助你安装和运行 GitLab。

sudo yum install -y curl policycoreutils openssh-server

3. 添加 GitLab 仓库

添加 GitLab 的官方仓库。

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

4. 安装 GitLab CE(社区版)

使用 yum 安装 GitLab Community Edition。

sudo yum install -y gitlab-ce

5. 配置 GitLab

在安装过程中,GitLab 会提示你进行一些配置,例如设置 GitLab 的域名和管理员密码。你可以根据需要进行配置。

6. 启动并启用 GitLab 服务

启动 GitLab 服务并设置为开机自启。

sudo systemctl start gitlab
sudo systemctl enable gitlab

7. 验证安装

打开浏览器并访问 http://<your_server_ip>,你应该能够看到 GitLab 的登录页面。使用你在安装过程中设置的管理员用户名和密码登录。

8. 配置 GitLab CI

GitLab CI 是 GitLab 的一部分,通常在安装 GitLab 后就可以使用。你需要创建一个 .gitlab-ci.yml 文件来定义你的 CI/CD 流程。

在你的项目根目录下创建一个 .gitlab-ci.yml 文件,并添加你的 CI/CD 配置。例如:

stages:
  - build
  - test

build_job:
  stage: build
  script:
    - echo "Building the project..."
    - # 你的构建脚本

test_job:
  stage: test
  script:
    - echo "Running tests..."
    - # 你的测试脚本

9. 提交 .gitlab-ci.yml 文件

.gitlab-ci.yml 文件提交到你的 GitLab 仓库中。

git add .gitlab-ci.yml
git commit -m "Add GitLab CI configuration"
git push origin master

一旦 .gitlab-ci.yml 文件被推送到仓库,GitLab CI 将自动开始运行你的 CI/CD 流程。

10. 监控 CI/CD 流程

你可以在 GitLab 的 Web 界面中监控 CI/CD 流程的进度和结果。

通过以上步骤,你应该能够在 CentOS 上成功安装并配置 GitLab CI。如果你遇到任何问题,可以参考 GitLab 的官方文档或寻求社区帮助。

0
看了该问题的人还看了