1. centos下gitlab runner安装
下载gitlab-runner,并进行安装,命令如下:
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
yum install gitlab-runner
2. GitLab-CI注册Runner
(1)执行下列注册命令
[root@localhost ~]# gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://192.168.2.141:9001/ (说明:token 如下图所示)
Please enter the gitlab-ci token for this runner:
yLxk5Eaj1jYXnAJS5*** (说明:token 如下图所示)
Please enter the gitlab-ci description for this runner:
[localhost.localdomain]: focus-runner-des (runner的描述名称,随便DIY能有效区分就行)
Please enter the gitlab-ci tags for this runner (comma separated):
192.168.2.107 (runner的tags名称,随便DIY能有效区分就行)
Please enter the executor: docker-ssh, parallels, ssh, virtualbox, kubernetes, docker, shell, docker+machine, docker-ssh+machine:
shell (因为想用shell脚本执行,所以选择shell,选择shell的优点是共享服务器上安装的java、maven以及docker等应用)
(2)注册完成后,项目的runner将会创建成功
(3)简单测试
项目下创建.gitlab-ci.yml ,使用模板文件进行测试runner是否可用
点击run pipeline进行测试,
3. 常见问题汇总
(1)连接项目时报错
fatal: unable to access 'http://gitlab-ci-token:xxxxxx@ip/xxx/citest.git/': Failed to connect to xx.xx.xx.xxx port 80: Connection refused
则可在/etc/gitlab-runner/config.toml文件里添加 clone_url = "xxx"
(2)gitlab CI/CD失败一次后,再次运行提示:
fatal: git fetch-pack: expected shallow list
fatal: The remote end hung up unexpectedly
原因是因为git版本太老不支持新的API
解决方法:升级git到最新的版本
#安装源
yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
#安装git
yum install git
#更新git
yum update git
(3)执行时日志过大,错误信息如下:
Job's log exceeded limit of 4194304 bytes.
Job execution will continue but no more output will be collected.
原因是因为gitlab-runner默认的日志大小为4M
解决方法:修改日志的存储大小,在/etc/gitlab-runner/config.toml中添加:
output_limit=81920 #可以根据需求自定义大小
(4)执行docker命令时报错提示promission denied
解决方法:将root用户添加到docker用户组
#则需要把将当前用户加入docker组
sudo gpasswd -a ${USER} docker
#查看docker用户组成员
cat /etc/group |grep docker
# 赋予权限
sudo chmod a+rw /var/run/docker.sock