理解了上面的基本概念之后,有没有觉得少了些什么东西 —— 由谁来执行这些构建任务呢?
答案就是 GitLab Runner 了!
想问为什么不是 GitLab CI 来运行那些构建任务?
一般来说,构建任务都会占用很多的系统资源 (譬如编译代码),而 GitLab CI 又是 GitLab 的一部分,如果由 GitLab CI 来运行构建任务的话,在执行构建任务的时候,GitLab 的性能会大幅下降。
GitLab CI 最大的作用是管理各个项目的构建状态,因此,运行构建任务这种浪费资源的事情就交给 GitLab Runner 来做拉!
因为 GitLab Runner 可以安装到不同的机器上,所以在构建任务运行期间并不会影响到 GitLab 的性能
在目标主机上安装 GitLab Runner,这里的目标主机指你要部署的服务器
Ubuntu 安装脚本:
Installing the Runner
Important: If you are using or upgrading from a version prior to GitLab Runner 10, read how to upgrade to the new version. If you want to install a version prior to GitLab Runner 10, visit the old docs.
To install the Runner:
Add GitLab’s official repository:
# For Debian/Ubuntu/Mint
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
# For RHEL/CentOS/Fedora
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
Note: Debian users should use APT pinning.
Install the latest version of GitLab Runner, or skip to the next step to install a specific version:
Note: Debian buster users should disable skel to prevent No such file or directory Job failures
# For Debian/Ubuntu/Mint
sudo apt-get install gitlab-runner
# For RHEL/CentOS/Fedora
sudo yum install gitlab-runner
# for DEB based systems
apt-cache madison gitlab-runner
sudo apt-get install gitlab-runner=10.0.0
# for RPM based systems
yum list gitlab-runner --showduplicates | sort -r
sudo yum install gitlab-runner-10.0.0-1
安装好 GitLab Runner 之后,我们只要启动 Runner 然后和 GitLab CI 绑定:
[root@iZbp1fmnx8oyubksjdk7leZ gitbook]# sudo gitlab-ci-multi-runner register
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://192.168.75.146:8080/
Please enter the gitlab-ci token for this runner:
1Lxq_f1NRfCfeNbE5WRh
Please enter the gitlab-ci description for this runner:
[iZbp1fmnx8oyubksjdk7leZ]: deploy-gaming
Please enter the gitlab-ci tags for this runner (comma separated):
deploy
Whether to run untagged builds [true/false]:
[false]: true
Whether to lock Runner to current project [true/false]:
[false]:
Registering runner... succeeded runner=P_zfkhTb
Please enter the executor: virtualbox, docker+machine, parallels, shell, ssh, docker-ssh+machine, kubernetes, docker, docker-ssh:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
说明:
出现New runner. Has not connected yet, 此时必须使用sudo gitlab-runner register 进行注册。
(很大程度上是跟是否使用sudo相关的,因为用户的不同会导致一些权限问题)
sudo passwd gitlab-runner
sudo gpasswd -a gitlab-runner root
su gitlab-runner
ssh-keygen -t rsa -C "你在 GitLab 上的邮箱地址"
cd
cd .ssh
cat id_rsa.pub
项目触发runner,一直处于pending
初步怀疑是runner卡住了,也有可能是因为服务器资源不足,在服务器上执行gitlab-ci-multi-runner list发现runer还在,
在执行gitlab-ci-multi-runner verify,发现runer还活着,但是就是一直不执行流程
有两个方法解决:
1、执行gitlab-ci-multi-runner run(不推荐使用)
他会去执行runner任务,但是每次都需要运行次命令才回去执行任务
2、执行 **gitlab-ci-multi-runner restart**
重启runner,发现他会自动去执行触发runner的任务