实战:GitLabRunner安装部署-2023.4.26(安装成功)
目录
实验环境
gitlab/gitlab-ce:15.0.3-ce.0
gitlab-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/
[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
--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
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... connected.
WARNING: cannot verify mirrors.tuna.tsinghua.edu.cn's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
Issued certificate has expired.
HTTP request sent, awaiting response... 200 OK
Length: 434734559 (415M) [application/x-redhat-package-manager]
Saving to: ‘gitlab-runner-15.0.1-1.x86_64.rpm’
100%[================================================================================================================================================================>] 434,734,559 14.3MB/s in 33s
2023-04-26 06:42:52 (12.4 MB/s) - ‘gitlab-runner-15.0.1-1.x86_64.rpm’ saved [434734559/434734559]
[root@Devops6 ~]#ll -h gitlab-runner-15.0.1-1.x86_64.rpm
-rw-r--r-- 1 root root 415M Jul 21 2022 gitlab-runner-15.0.1-1.x86_64.rpm
2、安装gitlab-runner rpm包
## 安装runner
[root@Devops6 ~]#rpm -ivh gitlab-runner-15.0.1-1.x86_64.rpm
warning: gitlab-runner-15.0.1-1.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 35dfa027: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-runner-15.0.1-1 ################################# [100%]
GitLab Runner: creating gitlab-runner...
Home directory skeleton not used
Runtime platform arch=amd64 os=linux pid=51841 revision=7674edc7 version=15.0.1
gitlab-runner: the service is not installed
Runtime platform arch=amd64 os=linux pid=51848 revision=7674edc7 version=15.0.1
gitlab-ci-multi-runner: the service is not installed
Runtime platform arch=amd64 os=linux pid=51872 revision=7674edc7 version=15.0.1
Runtime platform arch=amd64 os=linux pid=51908 revision=7674edc7 version=15.0.1
Check and remove all unused containers (both dangling and unreferenced) including volumes.
------------------------------------------------------------------------------------------
Total reclaimed space: 0B
3、验证
## 查看进程
[root@Devops6 ~]#ps aux|grep gitlab-runner
root 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
root 51995 0.0 0.0 112708 980 pts/0 S+ 06:44 0:00 grep --color=auto gitlab-runner
#查看版本
[root@Devops6 ~]#gitlab-runner -v
Version: 15.0.1
Git revision: 7674edc7
Git branch: 15-0-stable
GO version: go1.17.7
Built: 2022-07-20T15:13:22+0000
OS/Arch: linux/amd64
2、注册Runner
1、获取GitLab地址和Runner 注册token
- 本次注册平台级别runner:
点击Menu/Admin/Runners
:
保存下上面这个token:
osNyPCDx47f52iD4Hh5F
2、运行注册命令
- 开始交互式注册
[root@Devops6 ~]#gitlab-runner register
Runtime platform arch=amd64 os=linux pid=53427 revision=7674edc7 version=15.0.1
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://172.29.9.101:8076/
Enter the registration token:
osNyPCDx47f52iD4Hh5F
Enter a description for the runner:
[Devops6]: build01
Enter tags for the runner (comma-separated):
build,go,maven
Enter optional maintenance note for the runner:
Registering runner... succeeded runner=osNyPCDx
Enter an executor: parallels, shell, docker+machine, docker-ssh+machine, kubernetes, custom, docker, docker-ssh, ssh, virtualbox:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
说明:默认注册采用的交互式,需要交互填写信息。
[root@zeyang-nuc-service gitlab-runner]# gitlab-runner register
Runtime platform arch=amd64 os=linux pid=40969 revision=f188edd7 version=14.9.1
Running in system-mode.
## 输入GitLab实例的URL
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://192.168.1.200
## 输入Runner注册Token
Enter the registration token:
m5ucdGk2_uPJ2K9BP8-d
## 填写该注册Runner的描述信息
Enter a description for the runner:
[zeyang-nuc-service]: build runner
## 为该Runner配置一个标签(后续作业可以通过tag指定在哪个runner上面运行构建)
Enter tags for the runner (comma-separated):
build,go,maven
Enter optional maintenance note for the runner:
Registering runner... succeeded runner=m5ucdGk2
## 为Runner选择一个执行器
Enter an executor: docker, parallels, ssh, docker+machine, docker-ssh+machine, custom, docker-ssh, shell, virtualbox, kubernetes:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
- 本地查看runner信息
[root@Devops6 ~]#gitlab-runner list
Runtime platform arch=amd64 os=linux pid=53774 revision=7674edc7 version=15.0.1
Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml
build01 Executor=shell Token=PzMYek9JphRmM5Fo5qKo URL=http://172.29.9.101:8076/
[root@Devops6 ~]#gitlab-runner verify
Runtime platform arch=amd64 os=linux pid=53789 revision=7674edc7 version=15.0.1
Running in system-mode.
Verifying runner... is alive runner=PzMYek9J
- 当然也可以使用非交互模式来注册:
gitlab-runner register \
--non-interactive \
--url "http://192.168.1.200/" \
--registration-token "m5ucdGk2_uPJ2K9BP8-d" \
--executor "shell" \
--description "buildrunner" \
--tag-list "build,k8s,go" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
3、刷新GitLab管理页面
3、配置Runner
- 通过Gitlab后台可以看下runner的配置:
- gitlab-runner配置文件 (改完配置文件,它会自动生效的。)
[root@Devops6 ~]#cat /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "build01"
url = "http://172.29.9.101:8076/"
token = "PzMYek9JphRmM5Fo5qKo"
executor = "shell"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
说明:
concurrent = 1 ## 可并行运行作业的数量, 0表示不限制;
check_interval = 0 ## 检查新作业的时间间隔, 0表示默认 3秒;
[session_server] ## 允许用户与作业进行交互,例如web终端;
session_timeout = 1800
[[runners]]
name = "my first runner" ## Runner名称;
url = "http://192.168.1.200/" ## GitLab Server地址;
token = "z6QEqyGpDrvzNgfxLiVh" ## Runner token;
executor = "shell" ## Runner的执行器;
[runners.custom_build_dir] ## 允许用户为作业定义自定义构建目录;
[runners.cache] ## 分布式缓存目录;
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
高级配置参考: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscustom-section
4、Runner常用命令
- gitlab Runner常用命令
gitlab-runner register #默认交互模式下使用,非交互模式添加 --non-interactive
gitlab-runner list #此命令列出了保存在配置文件中的所有运行程序
gitlab-runner verify #此命令检查注册的runner是否可以连接,但不验证GitLab服务是否正在使用runner。 --delete 删除
gitlab-runner unregister #该命令使用GitLab取消已注册的runner。
#使用令牌注销
gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n
#使用名称注销(同名删除第一个)
gitlab-runner unregister --name test-runner
#注销所有
gitlab-runner unregister --all-runners
FAQ
升级完git版本后,gitlabrunner会被删除的
- 升级完git后,gitlab-runner没掉了,再次安装gitlab-runner时报错
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cfmdIB2l-1684397768919)(https://bucket-hg.oss-cn-shanghai.aliyuncs.com/img/image-20230510075035521.png)]
- 那就使用yum来安装依赖包,就可以解决问题了
[root@Devops6 ~]#yum install -y gitlab-runner-15.0.1-1.x86_64.rpm
centos8安装时报错
自己是在centos7上测试的,这里先做记录。
- 报错现象
- 解决办法
关于我
我的博客主旨:
- 排版美观,语言精炼;
- 文档即手册,步骤明细,拒绝埋坑,提供源码;
- 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!
🍀 微信二维码
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
最后
好了,关于本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!