1、安装gitlab Runner
本次演示为centos 7.5环境,请各位按照自己环境调整
1)在线安装
#安装官方镜像源 [root@k8s-node02 ~]# curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash #yum 安装gitlab Runner [root@k8s-node02 ~]# yum install gitlab-runner -y |
2)离线安装
- gitlab Runner下载地址:https://packages.gitlab.com/runner/gitlab-runner
-
服务器创建安装包位置
[root@k8s-node02 gitlab-runner]# mkdir -p /tools
- 下载gitlab-runner
[root@k8s-node02 gitlab-runner]# cd /tools/ [root@k8s-node02 tools]# ll total 0 [root@k8s-node02 tools]# wget https://packages.gitlab.com/runner/gitlab-runner/packages/fedora/29/gitlab-runner-12.6.0-1.x86_64.rpm/download.rpm [root@k8s-node02 tools]# ll total 49860 -rw-r--r-- 1 root root 51052604 Jan 19 22:45 gitlab-runner-12.6.0-1.x86_64.rpm
-
安装gitlab runner
#安装git [root@k8s-node02 tools]# yum install git -y #rpm离线安装gitlab runner,需要依赖git,所以请提前安装git [root@k8s-node02 tools]# rpm -ivh gitlab-runner-12.6.0-1.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:gitlab-runner-12.6.0-1 ################################# [100%]
- 提示:以上两种安装,请各位安装实际情况安装
- 指定gitlab-runner
[root@k8s-node02 ~]# useradd staff [root@k8s-node02 ~]# gitlab-runner uninstall Runtime platform arch=amd64 os=linux pid=25137 revision=ac8e767a version=12.6.0 [root@k8s-node02 ~]# gitlab-runner install --working-directory /home/staff --user staff Runtime platform arch=amd64 os=linux pid=25169 revision=ac8e767a version=12.6.0 [root@k8s-node02 staff]# vim /etc/systemd/system/gitlab-runner.service [root@k8s-node02 staff]# cat /etc/systemd/system/gitlab-runner.service [Unit] Description=GitLab Runner After=syslog.target network.target ConditionFileIsExecutable=/usr/lib/gitlab-runner/gitlab-runner [Service] StartLimitInterval=5 StartLimitBurst=10 ExecStart=/usr/lib/gitlab-runner/gitlab-runner "run" "--working-directory" "/home/staff" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--syslog" "--user" "staff" Restart=always RestartSec=120 [Install] WantedBy=multi-user.target
- 启动gitlab服务
[root@k8s-node02 ~]# systemctl daemon-reload #重新加载配置 [root@k8s-node02 tools]# /bin/systemctl start gitlab-runner #启动服务 [root@k8s-node02 tools]# /bin/systemctl enable gitlab-runner #设置开机启动 [root@k8s-node02 tools]# /bin/systemctl restart gitlab-runner #重启服务
- 验证服务是否启动
[root@k8s-node02 java_demo]# ps -ef |grep gitlab root 25339 1 0 01:16 ? 00:00:11 /usr/lib/gitlab-runner/gitlab-runner run --working-directory /home/staff --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user staff
- 设置权限
[root@k8s-node02 ~]# chown -R staff.staff /home/gitlab-runner
3)gitlab runner注册服务
-
安装了gitlab Runner之后,就可以为gitlab中的仓库注册一个Runner,注册的交互式命令如下:
[root@k8s-node02 ~]# gitlab-runner register
- 我们开始注册
[root@k8s-node02 ~]# gitlab-runner register Runtime platform arch=amd64 os=linux pid=6245 revision=ac8e767a version=12.6.0 Running in system-mode. #输入公司的gitlab公网地址 Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): http://192.168.200.133/ #输入gitlab的token,找到第三步token,然后选择第四步,复制token Please enter the gitlab-ci token for this runner: 8sjydnrsPuSRhKiQTQky #输入描述这个runner名称 Please enter the gitlab-ci description for this runner: [k8s-node02]: my-runner #输入runner的标签 Please enter the gitlab-ci tags for this runner (comma separated): my-tag,another-tag Registering runner... succeeded runner=8sjydnrs #输入runner执行器的环境 Please enter the executor: custom, docker-ssh, parallels, kubernetes, docker-ssh+machine, docker, shell, ssh, virtualbox, docker+machine: shell Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
- 验证gitlab runner是否注册成功
在验证的时候,请刷新界面,再次查看,验证
3)gitlab Runner常用命令汇总
命令 |
描述 |
gitlab-runner run |
运行一个runner服务 |
gitlab-runner register |
注册一个新的runner |
gitlab-runner start |
启动服务 |
gitlab-runner stop |
关闭服务 |
gitlab-runner restart |
重启服务 |
gitlab-runner status |
查看各个runner的状态 |
gitlab-runner unregister |
注销掉某个runner |
gitlab-runner list |
显示所有运行着的runner |
gitlab-runner verify |
检查已注册的运行程序是否可以连接到GitLab,但它不验证GitLab Runner服务是否正在使用运行程序。 |