前言
最近在阿里云服务器(Alibaba Cloud Linux 3)上部署 GitLab Runner,本以为是很简单的yum install和register,结果踩了一路的坑:从 yum 源 404,到新版 Token 注册参数报错,再到 SSH 模式的各种权限和握手失败。
折腾了一圈发现,对于GitLab 和 Runner 在同一台机器的场景,Shell 模式才是最香的。本文记录了完整的解决过程,希望能帮大家避坑。
环境信息
操作系统:Alibaba Cloud Linux 3 (兼容 CentOS 8 / RHEL 8)
GitLab 版本:较新版本(使用
glrt-开头的新架构 Token)部署架构:GitLab 和 Runner 部署在同一台服务器上
坑位一:安装时 Yum 源 404 报错
问题描述
在执行官方提供的安装脚本时:
Bash
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash报错提示:
Unable to download repo config...
curl: (22) The requested URL returned error: 404
原因分析
官方脚本无法识别alinux(Alibaba Cloud Linux) 这个发行版 ID,导致拼接下载链接时出错。由于该系统完全兼容 CentOS 8,我们可以强制指定系统版本。
✅ 解决方案
在运行脚本前,强制指定os=el和dist=8:
Bash
# 强制指定为 RHEL/CentOS 8 环境 curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo os=el dist=8 bash # 然后正常安装 sudo yum install gitlab-runner -y坑位二:SSH Executor 的无尽报错
问题尝试
最初我选择了ssh模式,希望 Runner 通过 SSH 登录本机执行任务。结果配置了一大堆 Key 路径后,报错连连:
权限错误:
open /root/.ssh/id_rsa: no such file or directory(gitlab-runner 用户无权访问 root 目录)。握手失败:
ssh: handshake failed: knownhosts: key is unknown(本机连本机也被拦截)。
💡 避坑建议
如果你的 Runner 就跑在目标服务器本机,千万不要用 SSH 模式!不仅配置繁琐,而且效率低。
直接用 Shell 模式,Runner 直接调用系统命令,简单粗暴且稳定。
坑位三:注册时的参数报错 (FATAL: Runner configuration...)
问题描述
使用新版 Token (glrt-xxxxx) 注册时,我想直接在命令行指定 tag 和配置:
Bash
gitlab-runner register --token "glrt-..." --tag-list "build" --run-untagged="true" ...结果直接报错:
FATAL: Runner configuration other than name and executor configuration is reserved...
原因分析
GitLab 新版架构中,使用 Authentication Token (glrt-) 注册时,禁止在命令行设置 tag、locked、access-level 等参数。这些配置必须注册完成后在 GitLab 网页端设置。
✅ 最终完美的注册命令 (Shell 模式)
Bash
gitlab-runner register \ --non-interactive \ --url "http://你的gitlabIP:端口" \ --token "glrt-你的Token" \ --executor "shell" \ --description "shell-runner-final"后续关键配置(不做跑不起来)
注册成功后,还没完!因为刚才命令行里不能传参,默认配置可能导致作业一直 Pending。
1. 开启“运行无标签作业”
进入 GitLab 项目 ->Settings->CI/CD->Runners。
点击 Runner 旁边的编辑(铅笔图标)。
勾选"Run untagged jobs"。
保存。
2. 正确启动服务
不要使用 gitlab-runner run(这是前台运行,关窗口就断了)。
生产环境请使用:
Bash
# 启动后台服务 gitlab-runner start # 确认状态为 Service is running gitlab-runner status验证效果
在项目根目录新建.gitlab-ci.yml进行测试:
YAML
stages: - test test-job: stage: test script: - echo "Shell Runner 部署成功!" - whoami - date提交代码后,查看流水线日志,成功输出!
总结
系统兼容:阿里 Linux 3 安装时需欺骗脚本
os=el dist=8。模式选择:本机部署首选Shell模式,避开 SSH 的坑。
新版语法:新 Token 注册时,命令行只管注册,配置去网页端点。
服务管理:用
start而不是run。
希望这篇记录能帮到大家,少走弯路!