gitlab是一个代码托管工具,开源。gitrunner是一个持续集成工具(CI CD),只要gitlab代码有提交,gitlab-runner就会自动部署。很方便。
gitlab-runner安装过程记录
centos7 安装
下载安装包
sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/v12.8.0/binaries/gitlab-runner-linux-amd64
释放目录权限
sudo chmod +x /usr/local/bin/gitlab-runner
安装
gitlab-runner install --user=root --working-directory=/home/gitlab-runner
启动
gitlab-runner start
gitlab-runner注册到gitlab的项目
1.首先在gitlab新建自己的项目,可以上传本地代码,也可以置空
在以下目录找到gitlab-runner的url和tokken
记住这两个信息
2.注册
gitlab-runner register
执行该命令后,会依次写入各个信息
# 注册
gitlab-runner register
# 输入本地的 gitlab URL
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://mesgit.seagate.com/
# 输入 Token
Please enter the gitlab-ci token for this runner
_FTHYNTYU747RzxFCYG
# 输入 tag, 注意要跟 job 的 tag 一致
Please enter the gitlab-ci tags for this runner (comma separated):
my-tag,another-tag
# 选择 executor,有docker选dokcer,没有选shell
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
shell
然后再第四步输入tag之后,我这里报错了,原因是x509: certificate signed by unknown authority,可见是证书问题,因为我的gitlab是https的,因此需要下载证书到gitlab-runner的机器上。
证书安装
到gitlab,点击小锁,选择certificate
选择copy to file导出浏览器的证书
上传到linux服务器,切换到openssl,执行x509 -inform der -in /root/x509.cer -out /root/x509.pem,生成linux的证书
执行cat /root/x509.pem >> /etc/pki/tls/certs/ca-bundle.crt,将证书添加到本机
然后重新注册,成功!
然后到gitlab查看runner,发现有runner了
ps:还有种情况,前面工作做完之后,gitlab这边会显示黑色的感叹号,显示New runner. Has not connected yet. 此问题在runner服务器执行gitlab-runner verify,再查看变成绿色了。
常用命令
gitlab-ruuner start #启动
gitlab-ruuner restart #重启
gitlab-ruuner stop #停止
gitlab-ruuner run #运行,运行之后gitlab上的runner会显示绿色,否则会显示New runner. Has not connected yet
gitlab-ruuner register #打开注册引导
卸载gitlab-runner
gitlab-runner stop
chkconfig gitlab-runner off
gitlab-runner uninstall
rm -rf /etc/gitlab-runner
rm -rf /usr/local/bin/gitlab-runner
rm -rf /usr/bin/gitlab-runner
rm -rf /etc/sudoers.d/gitlab-runner