(1)在gitlab上打开配置ci的项目,然后依次找到【setting】-【CICD】-【Runner】-【Expand】
(2)然后点击【Show Runner Installation Instruction】
(3)然后依次点击如下命令,在runner的linux机器上执行
(4)下载安装包
[root@iZbp1flzt6x7pxmxfhmxeeZ home]# sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 53.9M 100 53.9M 0 0 4908k 0 0:00:11 0:00:11 --:--:-- 6547k
[root@iZbp1flzt6x7pxmxfhmxeeZ home]#
(5)修改权限
[root@iZbp1flzt6x7pxmxfhmxeeZ home]# sudo chmod +x /usr/local/bin/gitlab-runner
[root@iZbp1flzt6x7pxmxfhmxeeZ home]#
(6)创建Gitlab Runner用户
[root@iZbp1flzt6x7pxmxfhmxeeZ home]# sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
[root@iZbp1flzt6x7pxmxfhmxeeZ home]#
(7)创建gitlab-runner软连接
[root@iZbp1flzt6x7pxmxfhmxeeZ home]# ln -s /usr/local/bin/gitlab-runner /usr/bin/gitlab-runner
[root@iZbp1flzt6x7pxmxfhmxeeZ home]#
(8)执行安装命令
[root@iZbp1flzt6x7pxmxfhmxeeZ home]# sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
Runtime platform arch=amd64 os=linux pid=13278 revision=4b9e985a version=14.4.0
[root@iZbp1flzt6x7pxmxfhmxeeZ home]#
(9)启动gitlab-runner服务
[root@iZbp1flzt6x7pxmxfhmxeeZ home]# sudo gitlab-runner start
Runtime platform arch=amd64 os=linux pid=13488 revision=4b9e985a version=14.4.0
[root@iZbp1flzt6x7pxmxfhmxeeZ home]#
(10)注册gitlab-runner
命令如下
sudo gitlab-runner register --url http://172.22.27.162/ --registration-token $REGISTRATION_TOKEN
这里需要将 $REGISTRATION_TOKEN 替换为具体的token值
token值通过如下位置复制
[root@iZbp1flzt6x7pxmxfhmxeeZ home]# sudo gitlab-runner register --url http://172.22.27.162/ --registration-token E_6cz-D_o4jz6nP6rPto
Runtime platform arch=amd64 os=linux pid=15050 revision=4b9e985a version=14.4.0
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
[http://172.22.27.162/]: http://172.22.27.162:8181/ # 此处需要和上图中的URL一致
Enter the registration token: # 此处直接回车
[E_6cz-D_o4jz6nP6rPto]:
Enter a description for the runner: # 描述,随便填
[iZbp1flzt6x7pxmxfhmxeeZ]: aliyun_shell
Enter tags for the runner (comma-separated): # 标签,后续CI中就是根据此处设置的标签选择runner,后面可继续修改
aliyun_shell,172.22.27.162
Registering runner... succeeded runner=E_6cz-D_
Enter an executor: shell, ssh, virtualbox, custom, docker-ssh, parallels, docker+machine, docker-ssh+machine, kubernetes, docker: # 此处因为是在linux上安装的,所以选择shell类型
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
[root@iZbp1flzt6x7pxmxfhmxeeZ home]#