### 在需要部署的服务器中首先需要安装gitlab-runner
- 下载二进制文件
# Linux x86-64<br/>
`sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64<br/>`<br/>
- 执行权限
`sudo chmod +x /usr/local/bin/gitlab-runner`
- 创建一个GitLab CI用户
`sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash`
- 安装并作为服务运行
`sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner`
`sudo gitlab-runner start`
<br/>
#### 安装完成runner后
- 注册runner
执行
`gitlab-ci-multi-runner register`
- 启动runner
`gitlab-ci-multi-runner start`
1.输入Gitlab CI地址<br/>
2.输入项目CI token<br/>
3.输入 Runner 描述<br/>
4.输入 Runner 标签,可以多个,用逗号隔开<br/>
5.输入 Runner 执行的语言<br/>
#### 完成,此时在gitlab-Settings-Runners中即会出现该runner信息,可以在做些细微调整等
[参考链接2](https://www.jianshu.com/p/705428ca1410)
gitlab-ci 配置
1.从 gitlab 菜单 Settings -> CI/CD 中展开 Runners 选项,会看到 Setup a specific Runner manually 说明,里面的 URL token 会在注册时用到。
2.登陆 gitlab-runner 机器,然后运行 gitlab-runner register,分别输入以下内容
[root@office-10-200-240-10-241-70 /]# gitlab-runner register
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://gitlab.17zuoye.net/
Please enter the gitlab-ci token for this runner:
输入第 1 步中的 token。
Please enter the gitlab-ci description for this runner:
[office-10-200-240-10-241-70]: 输入描述
Please enter the gitlab-ci tags for this runner (comma separated):
输入 yml 文件中的 tag
Registering runner... succeeded runner=W_7hD11x
Please enter the executor: kubernetes, docker, docker-ssh, parallels, shell, virtualbox, ssh, docker+machine, docker-ssh+machine:
ssh
Please enter the SSH server address (e.g. my.server.com):
输入要部署的机器IP
Please enter the SSH server port (e.g. 22):
Please enter the SSH user (e.g. root):
root
Please enter the SSH password (e.g. docker.io):
Please enter path to SSH identity file (e.g. /home/user/.ssh/id_rsa):
/root/.ssh/id_rsa_17zuoye_test.test
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
3.配置完成后运行 gitlab-runner list,会看到已经配置的所有 runner
Listing configured runner ConfigFile=/etc/gitlab-runner/config.toml
manage-ui-test Executor=ssh Token=${token} URL=${URL}
4.如果配置的有错误,可以使用命令 gitlab-runner unregister --url ${URL} --token ${token} 命令进行删除,注意这里的变量 ${token} 要使用步骤 3 中的 token,不能使用步骤 1 中的 token,否则会删除失败。
如果在gitlab网页端删除runner,gitlab-runner list 还会查到此runner的,gitlab-runner unregister对此runner会删除失败,可以尝试gitlab-runner verify --delete 删除无效的runner。
网友评论