Gitlab Runner 注册失败

Gitlab Runner Failed to register

我有一个带有 public IP 设置和 运行 的 gitlab 实例。但是,尝试添加 gitlab-runner 失败,因为对 runner 的反向查找似乎没有按预期工作。注册跑步者时,我可以在 gitlab 实例

的 nginx 上看到一个传入的 POST 请求,HTTP 状态为 200
1.2.3.4 - - [09/Oct/2021:21:41:51 +0200] "POST /api/v4/runners HTTP/1.1" 200 179 "-" "gitlab-runner 14.3.2 (14-3-stable; go1.13.8; linux/amd64)"

但跑者注册失败

 sudo gitlab-runner --debug register --non-interactive --url https://gitlab.example.org/ --registration-token asdasdasdasd --executor shell --tag-list shared --run-untagged=true --locked=false --access-level=not_protected
Runtime platform                                    arch=amd64 os=linux pid=2488 revision=e0218c92 version=14.3.2
Checking runtime mode                               GOOS=linux uid=0
Running in system-mode.                            
                                                   
Dialing: tcp gitlab.example.org:443 ...         
ERROR: Registering runner... failed                 runner=LQ_-Gq-k status=200 OK
PANIC: Failed to register the runner. You may be having network problems. 

该消息有点误导...

如何在建立连接后显示 gitlab 中发生的情况?我的意思是 HTTP 响应正式为 200。

runner 在 NAT 后面运行并且没有 public IP,但是 gitlab 实例有。路由和 DNS 设置正在工作以能够解析跑步者。

Gitlab 运行 在 Nginx 反向代理后面,但代理不受 gitlab-ctl 控制。由于这是全新安装,我检查了我的虚拟主机定义并认为可能是这种情况,因为传入的注册请求似乎被 nginx 以某种方式吃掉了。 gitlab-ctl tail 甚至没有记录注册 运行ner 的传入请求。

基于这个假设,我在 gitlab.rb

中启用了 gitlab 附带的 nginx
nginx['enable'] = true

和运行 gitlab-ctl reconfigure只是为了在gitlab.rb之后禁用nginx

nginx['enable'] = false

又是运行gitlab-ctl reconfigure

在该过程之后,nginx 配置在 /var/opt/gitlab/nginx/conf/ 中。我用 gitlab-http.conf 替换了我的 vhost 定义并进一步调整它。

现在一切正常。我的虚拟主机模板完全过时了。

我用的是ddns,所以需要通过修改hosts文件来解析域名,我的是ubuntu:

/etc/hosts

添加你的gitlab服务器ip的ip地址,像这样:

192.168.2.180  yourgitlab.yourdomain.com

然后,再次执行gitlab-runner注册,应该会成功。

sudo gitlab-runner register --url https://<yourgitlab.yourdomain.com> --registration-token <your token>