gitlab-runner 部署与踩坑

前言

去年花时间研究了一下 CI/CD , 自己部署了一套 gitlab-runner 玩了一下,部署过程之后遇到了不少问题,把之前的踩坑与部署记录分享一下。

简介

gitlab-runner是一个开源项目,用于运行 Pipeline 作业并将结果发送回 GitLab。

它与 GitLab CI 一起使用,GitLab CI是GitLab随附的开源持续集成服务,用于协调作业。

gitlab-runner是用 Go 编写,可以作为单个二进制文件运行,不需要语言特定的要求。

官方安装文档

gitlab-runner 安装官方文档:docs.gitlab.com/runner/inst...

gitlab-runner的三种类型:

  • 共享Runner(Shared Runner),所有项目可以使用。
  • 群组Runner(Group Runner),特定群组里的所有项目和子群组。
  • 特定Runner(Specific Runner),用于独立的项目。

gitlab-runner两种状态:

  • locked:无法运行项目作业

  • paused:不会运行作业

一、安装需知

  • gitlab runner 与 gitlab 版本尽量一致,差距过大部署会报错
  • 安装 gitlab-runner 依赖 git, 需要先安装 git
  • linux自带的git是1.8版本, 使用 runner 拉代码时会报错,升级至且大于 2.x 版本

本文版本说明

  • Git: 2.36.1
  • Gitlab: 14.7
  • GitlabRunner:15.3.0

二、下载与安装

1. 下载对应版本的 gitlab-runner 包

使用清华源下载 x86_64 架构安装包 ,官方地址可能没有 x86_64 架构安装包

shell 复制代码
sudo curl -L --output /usr/local/bin/gitlab-runner-15.3.0-1.x86_64.rpm https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-15.3.0-1.x86_64.rpm"

2. 安装下载后的 rpm 包

shell 复制代码
rpm -ivh gitlab-runner-15.3.0-1.x86_64.rpm

三、安装与启动

1. 查看当前服务运行情况

shell 复制代码
gitlab-runner status
  • 如下图所示,返回 Service is running 则表示服务正在运行中
  • 如显示: the service is not installedService is stop 运行启动命令后在查看

有时候,虽然显示为 the service is not installed 但实际已经完成安装,并能正常执行运行命令

2. 启动 gitlab-runner 服务

shell 复制代码
gitlab-runner start
  • 成功启动如下图所示
  • 如提示 the service is not installed 则执行一下安装命令
shell 复制代码
gitlab-runner install --working-directory /home/gitlab-runner --user root

3. 查看服务运行状态

该命令和 gitlab-runner status 的区别是,可以更直观的看到运行状态

shell 复制代码
systemctl status gitlab-runner

成功运行如下图所示:

如显示下图中的错误,请检查指定的 working-directory 目录是否存在,不存在则手动创建一个

相关 issue:gitlab.com/gitlab-org/...

相关推荐
想用offer打牌40 分钟前
MCP (Model Context Protocol) 技术理解 - 第二篇
后端·aigc·mcp
崔庆才丨静觅1 小时前
hCaptcha 验证码图像识别 API 对接教程
前端
passerby60612 小时前
完成前端时间处理的另一块版图
前端·github·web components
KYGALYX2 小时前
服务异步通信
开发语言·后端·微服务·ruby
掘了2 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
崔庆才丨静觅2 小时前
实用免费的 Short URL 短链接 API 对接说明
前端
崔庆才丨静觅3 小时前
5分钟快速搭建 AI 平台并用它赚钱!
前端
爬山算法3 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
崔庆才丨静觅3 小时前
比官方便宜一半以上!Midjourney API 申请及使用
前端
Moment3 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端