返回文章列表
安装配置 | 2024-04-08

如何在 Debian 上安装运行极狐GitLab Runner?

小马哥
极狐GitLab DevOps 技术布道师

极狐GitLab 是一个一体化的 DevOps 平台,CI/CD 是内置的功能,这也就是常说的极狐GitLab CI 要做的工作。而实现极狐GitLab CI 的核心组件是极狐GitLab Runner  —— 一个轻量级、高扩展的代理,用来运行你的 CI/CD 作业并且将结果发送回极狐GitLab 实例。极狐GitLab Runner 和极狐GitLab CI/CD 绑定在一起。

 

极狐GitLab Runner 支持多种操作系统:

 

  • CentOS
  • Debina
  • Ubuntu
  • RHEL
  • Fedora
  • Mint
  • Oracle
  • Amazon

 

也支持多种 CPU 架构:

 

  • x86
  • AMD64
  • ARM64
  • ARM
  • s390x
  • ppc64le

 

而且也支持多种安装方式:源码、软件包、二进制文件以及容器安装。

 

本文演示在 Debian 12 上安装配置极狐GitLab 的两种方式:二进制安装 & 容器化安装。

 

 

软件包安装

 

下载安装包并安装

 

使用如下命令下载 Runner 安装包并查看:

 

$ curl -LJO "https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_${arch}.deb"

$ ls -ltr
-rw-r--r-- 1 root root 491857186 Mar 26 11:35 gitlab-runner_amd64.deb

 

执行如下命令即可完成安装:

 

$ dpkg -i gitlab-runner_amd64.deb

Selecting previously unselected package gitlab-runner.
(Reading database ... 64318 files and directories currently installed.)
Preparing to unpack gitlab-runner_amd64.deb ...
Unpacking gitlab-runner (16.10.0-1) ...
Setting up gitlab-runner (16.10.0-1) ...
GitLab Runner: creating gitlab-runner...
Home directory skeleton not used
Runtime platform                                    arch=amd64 os=linux pid=226784 revision=81ab07f6 version=16.10.0
gitlab-runner: the service is not installed
Runtime platform                                    arch=amd64 os=linux pid=226796 revision=81ab07f6 version=16.10.0
gitlab-ci-multi-runner: the service is not installed
Runtime platform                                    arch=amd64 os=linux pid=226830 revision=81ab07f6 version=16.10.0
Runtime platform                                    arch=amd64 os=linux pid=226876 revision=81ab07f6 version=16.10.0

Check and remove all unused containers (both dangling and unreferenced) including volumes.
------------------------------------------------------------------------------------------
Total reclaimed space: 0B

 

通过 --version查看安装是否成功:

 

$ gitlab-runner --version
Version:      16.10.0
Git revision: 81ab07f6
Git branch:   16-10-stable
GO version:   go1.21.7
Built:        2024-03-21T19:43:25+0000
OS/Arch:      linux/amd64

 

注册 Runner 

 

在极狐GitLab 上选定项目,在设置 --> CI/CD --> --> Runner中在项目 Runner 中选择新建项目 Runner

 

 

 

点击新建项目 Runner,填写所需的信息,然后点击创建 runner

 

 

在出现的界面中会给出 Runner 注册的命令(同时也会包含 Runner 注册的 token,此 token 需要好好保存):

 

 

copy 上面的命令注册 Runner:

 

$ gitlab-runner register  --url https://jihulab.com  --token glrt-SYhzxxxxx5KDhZU

Enter the GitLab instance URL (for example, https://gitlab.com/):
[https://jihulab.com]: https://jihulab.com
Verifying runner... is valid                        runner=SYhzyjbEb
Enter a name for the runner. This is stored only in the local config.toml file:
[VM-20-9-debian]: debian-runner
Enter an executor: parallels, docker-autoscaler, docker+machine, kubernetes, custom, shell, ssh, virtualbox, docker, docker-windows, instance:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"

输入必要的信息即可完成 Runner 注册。

 

参数说明:

 

--url:极狐GitLab 实例的地址,可以是私有化部署实例的地址,也可以是 SaaS 地址(https://jihulab.com) 

--token:runner 的注册 token。

 

这时候就可以在项目 --> 设置 --> CI/CD --Runner 页面看到注册成功的 Runner 了:

 

 

测试 Runner 

 

选择一个需要构建 CI/CD 的极狐GitLab 项目,创建一个 .gitlab-ci.yml文件,选择一个内置的 bash模版:

 

 

 

在 stage中用 tags使用刚注册成功 Runner:

 

tags:
  - debian

 

提交变更即可触发 CI/CD 流水线:

 

 

可以看到流水线构建成功,查看作业的构建日志:

 

 

 

 

从日志可以看出作业就是刚才注册成功的 Runner 上执行的,因为注册时候给 Runner 取名为 debian-runner

 

 

用容器的方式安装

 

首先要确保有 docker环境。用 info或 version查看即可:

 

docker version
Client: Docker Engine - Community
 Version:           26.0.0
 API version:       1.45
 Go version:        go1.21.8
 Git commit:        2ae903e
 Built:             Wed Mar 20 15:18:01 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.0.0
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       8b79278
  Built:            Wed Mar 20 15:18:01 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

 

 

创建 Runner

 

使用如下命令创建一个 Runner:

 

$ docker run -d --name debian-gitlab-runner --restart always   -v $PWD:/etc/gitlab-runner    gitlab/gitlab-runner:latest

 

查看创建成功的容器:

 

$ docker ps
CONTAINER ID   IMAGE                         COMMAND                  CREATED          STATUS          PORTS     NAMES
5dfe6ca004bc   gitlab/gitlab-runner:latest   "/usr/bin/dumb-init …"   36 seconds ago   Up 35 seconds             debian-gitlab-runner

 

注册 Runner

 

同样使用前面的方法创建 Runner token,并使用如下命令注册 Runner:

 

$ gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=30 revision=81ab07f6 version=16.10.0
Running in system-mode.

Enter the GitLab instance URL (for example, https://gitlab.com/):
https://jihulab.com
Enter the registration token:
GR1348941xBNuxxxR1EvA4XjbqSz
Enter a description for the runner:
[5dfe6ca004bc]: docker-runner
Enter tags for the runner (comma-separated):
debina,docker
Enter optional maintenance note for the runner:
debian installation runner
WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://docs.gitlab.com/ee/ci/runners/new_creation_workflow
Registering runner... succeeded                     runner=GR1348941xBNuGoeh
Enter an executor: docker-autoscaler, instance, custom, shell, ssh, parallels, docker+machine, kubernetes, virtualbox, docker, docker-windows:
docker
Enter the default Docker image (for example, ruby:2.7):
alpine:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"

 

同样可以在 Runner 界面上看到注册成功的 Runner:

 

 

 

测试 Runner

 

用同样的项目,测试一下 Runner。

 

 

从最顶部的 log 看使用的是用 docker 安装的 Runner 运行的此次 CI/CD。

极狐GitLab 一体化DevOps平台 专为中国用户研发,免费试用60天专业版高级功能
售前咨询
联系电话
在线支持
预约演示