目录
- 概述
- 资源
- 官方资源
- 离线资源
- 操作
- 环境验证
- gitlab-runner安装
- 注意事项
- 重启
- 向gitlab注册
- CICD流程测试
概述
gitlab此文使用rpm离线安装的方式,使用 gitlab-runner
dockerfile构建运行环境: 如有兴趣可以参考这篇文章
gitlab选择 docker-compose
执行 docker
部署,gitlab-runner
选择 rpm
方式安装,也有使用 dockerfile
构建整个 cicd
环境。
整体执行图如下:
gitlab安装参考
资源
官方资源
gitlab-runner官网下载地址
离线资源
此资源在本章节中得到了验证。
离线资源地址
操作
环境验证
验证 jdk 、maven、docker 的版本
[root@hadoop01 ~]# mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /root/apache-maven-3.8.1
Java version: 1.8.0_261, vendor: Oracle Corporation, runtime: /root/jdk1.8.0_261/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "5.4.274-1.el7.elrepo.x86_64", arch: "amd64", family: "unix"
[root@hadoop01 ~]# docker version
Client:
Version: 24.0.5
API version: 1.41 (downgraded from 1.43)
Go version: go1.20.6
Git commit: ced0996
Built: Fri Jul 21 20:34:32 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:46:12 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@hadoop01 ~]#
gitlab-runner安装
[root@hadoop01 ~]# rpm -ivh download.rpm
警告:download.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 35dfa027: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:gitlab-runner-13.8.0-1 ################################# [100%]
GitLab Runner: creating gitlab-runner...
Runtime platform arch=amd64 os=linux pid=16032 revision=775dd39d version=13.8.0
gitlab-runner: Service is not running.
Runtime platform arch=amd64 os=linux pid=16046 revision=775dd39d version=13.8.0
gitlab-ci-multi-runner: Service is not running.
Runtime platform arch=amd64 os=linux pid=16089 revision=775dd39d version=13.8.0
Runtime platform arch=amd64 os=linux pid=16133 revision=775dd39d version=13.8.0
Clearing docker cache...
注意事项
修改一下 gitlab-runner 用户
- 可将gitlab-runner运行的账号修改为root,将权限升级–user gitlab-runner 修改为 –user root
- 注意gitlab-runner默认路径,/home/gitlab-runner需要注意此目录的磁盘大小
或者执行如下命令
# 查看运行容器用户信息
ps -u | grep gitlab-runner
# 将gitlab加入docker用户组
usermod -aG docker gitlab-runner
# 刷新docker用户组
newgrp docker
重启
[root@hadoop01 ~]# systemctl daemon-reload
[root@hadoop01 ~]# systemctl restart gitlab-runner.service
[root@hadoop01 ~]# systemctl status gitlab-runner.service
● gitlab-runner.service - GitLab Runner
Loaded: loaded (/etc/systemd/system/gitlab-runner.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2024-05-30 15:35:38 CST; 2s ago
Main PID: 25470 (gitlab-runner)
Tasks: 12
Memory: 11.1M
CGroup: /system.slice/gitlab-runner.service
└─25470 /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --user root
向gitlab注册
[root@hadoop01 ~]# gitlab-runner register
Runtime platform arch=amd64 os=linux pid=27450 revision=775dd39d version=13.8.0
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://10.xx.xx.142:8088/
Enter the registration token:
zTmKegWEfStFWa5hCbhR
Enter a description for the runner:
[hadoop01]: test
Enter tags for the runner (comma-separated):
test,prod
Registering runner... succeeded runner=zTmKegWE
Enter an executor: parallels, shell, virtualbox, docker-ssh+machine, docker, docker-ssh, docker+machine, kubernetes, custom, ssh:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
CICD流程测试
镜像也上传至私服上了