GitLabRunner安装部署
实战:GitLabRunner安装部署-2023.4.26(安装成功)

目录
[toc]
实验环境
1gitlab/gitlab-ce:15.0.3-ce.0
2gitlab-runner-15.0.1-1.x86_64.rpm
实验软件
链接:https://pan.baidu.com/s/10aL_kWzDKnZXBXG3-hS2tA
提取码:0820
2023.4.26-实战:GitLabRunner安装部署-(安装成功)

什么是Gitlab runner

- GitLab Runner是一个开源项目,用于运行作业并将结果发送回GitLab。
- 与GitLabCI结合使用,GitLabCI是GitLab随附的用于协调作业的开源持续集成服务。
- GitLab Runner是用Go编写的,可以在Linux,macOS和Windows操作系统上运行。
- 容器部署需使用最新Docker版本。GitLab Runner需要最少的Docker v1.13.0。
- GitLab Runner版本应与GitLab版本同步。(避免版本不一致导致差异化)
- 可以根据需要配置任意数量的Runner。

注意:建议将runner和gitlab server放在不同机器上运行,否则可能不能正常运行,并且也会给servre带来性能上的影响。
本次是实验环境,是可以使用同的一台机器!(gitlab是容器方式,而gitlab Runner是直接跑在宿主机上的,类似于jenkins master是以容器方式运行,而agent是直接跑在宿主机上的)!
类型
- shared 共享类型,运行整个平台项目的作业**(gitlab)**
- group 项目组类型,运行特定group下的所有项目的作业**(group)**
- specific项目类型,运行指定的项目作业**(project)**
后面我们都是在平台类型上注册runner的:(注册时需要带上token)

平台级别的runner:

组级别的runner:

项目,这里也是可以看到3种runner类型的。

状态
- locked: 锁定状态,无法运行项目作业
- paused: 暂停状态,暂时不会接受新的作业
步骤
- 安装
gitlab-runner工具 - 使用
gitlab-runner工具向GitLab Server注册Runner节点。
1、Runner安装
在Linux系统安装GR
- 基于Linux CentOS8操作系统, 部署GitLabRunner。
GitLab部署包下载:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el8/
Runner部署包下载:https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el8-x86_64/
自己本次测试:
1、下载gitlab-runner安装包
查看自己gitlab版本,下载和当前gitlab差不多一致的gitlab-runner安装包


Runner部署包下载:
https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7-x86_64/
1[root@Devops6 ~]#wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-15.0.1-1.x86_64.rpm --no-check-certificate
2--2023-04-26 06:42:18-- https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-15.0.1-1.x86_64.rpm
3Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
4Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... connected.
5WARNING: cannot verify mirrors.tuna.tsinghua.edu.cn's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
6 Issued certificate has expired.
7HTTP request sent, awaiting response... 200 OK
8Length: 434734559 (415M) [application/x-redhat-package-manager]
9Saving to: ‘gitlab-runner-15.0.1-1.x86_64.rpm’
10
11100%[================================================================================================================================================================>] 434,734,559 14.3MB/s in 33s
12
132023-04-26 06:42:52 (12.4 MB/s) - ‘gitlab-runner-15.0.1-1.x86_64.rpm’ saved [434734559/434734559]
14[root@Devops6 ~]#ll -h gitlab-runner-15.0.1-1.x86_64.rpm
15-rw-r--r-- 1 root root 415M Jul 21 2022 gitlab-runner-15.0.1-1.x86_64.rpm
2、安装gitlab-runner rpm包
1## 安装runner
2[root@Devops6 ~]#rpm -ivh gitlab-runner-15.0.1-1.x86_64.rpm
3warning: gitlab-runner-15.0.1-1.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 35dfa027: NOKEY
4Preparing... ################################# [100%]
5Updating / installing...
6 1:gitlab-runner-15.0.1-1 ################################# [100%]
7GitLab Runner: creating gitlab-runner...
8Home directory skeleton not used
9Runtime platform arch=amd64 os=linux pid=51841 revision=7674edc7 version=15.0.1
10gitlab-runner: the service is not installed
11Runtime platform arch=amd64 os=linux pid=51848 revision=7674edc7 version=15.0.1
12gitlab-ci-multi-runner: the service is not installed
13Runtime platform arch=amd64 os=linux pid=51872 revision=7674edc7 version=15.0.1
14Runtime platform arch=amd64 os=linux pid=51908 revision=7674edc7 version=15.0.1
15
16Check and remove all unused containers (both dangling and unreferenced) including volumes.
17------------------------------------------------------------------------------------------
18Total reclaimed space: 0B
3、验证
1## 查看进程
2[root@Devops6 ~]#ps aux|grep gitlab-runner
3root 51916 1.1 0.1 748072 18532 ? Ssl 06:44 0:00 /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --user gitlab-runner
4root 51995 0.0 0.0 112708 980 pts/0 S+ 06:44 0:00 grep --color=auto gitlab-runner
5
6
7#查看版本
8[root@Devops6 ~]#gitlab-runner -v
9Version: 15.0.1
10Git revision: 7674edc7
11Git branch: 15-0-stable
12GO version: go1.17.7
13Built: 2022-07-20T15:13:22+0000
14OS/Arch: linux/amd64
2、注册Runner
1、获取GitLab地址和Runner 注册token
- 本次注册平台级别runner:
点击Menu/Admin/Runners:


保存下上面这个token:
osNyPCDx47f52iD4Hh5F
2、运行注册命令
- 开始交互式注册
1[root@Devops6 ~]#gitlab-runner register
2Runtime platform arch=amd64 os=linux pid=53427 revision=7674edc7 version=15.0.1
3Running in system-mode.
4
5Enter the GitLab instance URL (for example, https://gitlab.com/):
6http://172.29.9.101:8076/
7Enter the registration token:
8osNyPCDx47f52iD4Hh5F
9Enter a description for the runner:
10[Devops6]: build01
11Enter tags for the runner (comma-separated):
12build,go,maven
13Enter optional maintenance note for the runner:
14
15Registering runner... succeeded runner=osNyPCDx
16Enter an executor: parallels, shell, docker+machine, docker-ssh+machine, kubernetes, custom, docker, docker-ssh, ssh, virtualbox:
17shell
18Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

说明:默认注册采用的交互式,需要交互填写信息。
1[root@zeyang-nuc-service gitlab-runner]# gitlab-runner register
2Runtime platform arch=amd64 os=linux pid=40969 revision=f188edd7 version=14.9.1
3Running in system-mode.
4## 输入GitLab实例的URL
5Enter the GitLab instance URL (for example, https://gitlab.com/):
6http://192.168.1.200
7
8## 输入Runner注册Token
9Enter the registration token:
10m5ucdGk2_uPJ2K9BP8-d
11
12## 填写该注册Runner的描述信息
13Enter a description for the runner:
14[zeyang-nuc-service]: build runner
15
16## 为该Runner配置一个标签(后续作业可以通过tag指定在哪个runner上面运行构建)
17Enter tags for the runner (comma-separated):
18build,go,maven
19Enter optional maintenance note for the runner:
20
21Registering runner... succeeded runner=m5ucdGk2
22## 为Runner选择一个执行器
23Enter an executor: docker, parallels, ssh, docker+machine, docker-ssh+machine, custom, docker-ssh, shell, virtualbox, kubernetes:
24shell
25Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
- 本地查看runner信息
1[root@Devops6 ~]#gitlab-runner list
2Runtime platform arch=amd64 os=linux pid=53774 revision=7674edc7 version=15.0.1
3Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml
4build01 Executor=shell Token=PzMYek9JphRmM5Fo5qKo URL=http://172.29.9.101:8076/
5[root@Devops6 ~]#gitlab-runner verify
6Runtime platform arch=amd64 os=linux pid=53789 revision=7674edc7 version=15.0.1
7Running in system-mode.
8
9Verifying runner... is alive runner=PzMYek9J

- 当然也可以使用非交互模式来注册:
1gitlab-runner register \
2 --non-interactive \
3 --url "http://192.168.1.200/" \
4 --registration-token "m5ucdGk2_uPJ2K9BP8-d" \
5 --executor "shell" \
6 --description "buildrunner" \
7 --tag-list "build,k8s,go" \
8 --run-untagged="true" \
9 --locked="false" \
10 --access-level="not_protected"
11
12
13#本次测试虚机代码
14gitlab-runner register \
15 --non-interactive \
16 --url "http://172.29.9.101:8076/" \
17 --registration-token "osNyPCDx47f52iD4Hh5F" \
18 --executor "shell" \
19 --description "buildrunner" \
20 --tag-list "build,mvn,go" \
21 --run-untagged="true" \
22 --locked="false" \
23 --access-level="not_protected"
3、刷新GitLab管理页面

3、配置Runner
- 通过Gitlab后台可以看下runner的配置:


- gitlab-runner配置文件 (改完配置文件,它会自动生效的。)
1[root@Devops6 ~]#cat /etc/gitlab-runner/config.toml
2concurrent = 1
3check_interval = 0
4
5[session_server]
6 session_timeout = 1800
7
8[[runners]]
9 name = "build01"
10 url = "http://172.29.9.101:8076/"
11 token = "PzMYek9JphRmM5Fo5qKo"
12 executor = "shell"
13 [runners.custom_build_dir]
14 [runners.cache]
15 [runners.cache.s3]
16 [runners.cache.gcs]
17 [runners.cache.azure]
说明:
1concurrent = 1 ## 可并行运行作业的数量, 0表示不限制;
2check_interval = 0 ## 检查新作业的时间间隔, 0表示默认 3秒;
3
4[session_server] ## 允许用户与作业进行交互,例如web终端;
5 session_timeout = 1800
6
7[[runners]]
8 name = "my first runner" ## Runner名称;
9 url = "http://192.168.1.200/" ## GitLab Server地址;
10 token = "z6QEqyGpDrvzNgfxLiVh" ## Runner token;
11 executor = "shell" ## Runner的执行器;
12 [runners.custom_build_dir] ## 允许用户为作业定义自定义构建目录;
13 [runners.cache] ## 分布式缓存目录;
14 [runners.cache.s3]
15 [runners.cache.gcs]
16 [runners.cache.azure]
高级配置参考: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscustom-section
4、Runner常用命令
- gitlab Runner常用命令
1gitlab-runner register #默认交互模式下使用,非交互模式添加 --non-interactive
2gitlab-runner list #此命令列出了保存在配置文件中的所有运行程序
3gitlab-runner verify #此命令检查注册的runner是否可以连接,但不验证GitLab服务是否正在使用runner。 --delete 删除
4gitlab-runner unregister #该命令使用GitLab取消已注册的runner。
5
6#使用令牌注销
7gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n
8
9#使用名称注销(同名删除第一个)
10gitlab-runner unregister --name test-runner
11
12#注销所有
13gitlab-runner unregister --all-runners
FAQ
升级完git版本后,gitlabrunner会被删除的
- 升级完git后,gitlab-runner没掉了,再次安装gitlab-runner时报错

- 那就使用yum来安装依赖包,就可以解决问题了
1[root@Devops6 ~]#yum install -y gitlab-runner-15.0.1-1.x86_64.rpm


centos8安装时报错
自己是在centos7上测试的,这里先做记录。
- 报错现象

- 解决办法

注意:runner的Run untagged jobs配置
默认是勾选了的。


关于我
我的博客主旨:
- 排版美观,语言精炼;
- 文档即手册,步骤明细,拒绝埋坑,提供源码;
- 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!
🍀 微信二维码 x2675263825 (舍得), qq:2675263825。

🍀 微信公众号 《云原生架构师实战》

🍀 语雀
https://www.yuque.com/xyy-onlyone

🍀 csdn https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

🍀 知乎 https://www.zhihu.com/people/foryouone

最后
好了,关于本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!

