Gitlab CI-3.遇到的問題


遇到的問題

1. cannot validate certificate for x.x.x.x because it doesn't contain any IP SANs

報錯信息:ERROR: Registering runner... failed runner=xxxxxxx status=couldn't execute POST against https://x.x.x.x/api/v4/runners: Post https://x.x.x.x/api/v4/runners: x509: cannot validate certificate for x.x.x.x because it doesn't contain any IP SANs

原因:gitlab使用自簽名證書時,注冊時需要使用對應的ca根證書驗證。

解決方案:注冊時,使用"--tls-ca-file"參數,指定自簽名的ca根證書。

2. certificate signed by unknown authority

報錯信息:Post https://x.x.x.x/api/v4/runners: x509: certificate signed by unknown authority

原因:注冊runner時,如果設置了"--tag-list",則"--run-untagged"默認為"false",同時間.gitlab-ci.yml中的job未指定tag觸發此報錯。

解決方案:注冊時,"--run-untagged"參數設置為"true";或者在已注冊的runner中修改勾選" Indicates whether this runner can pick jobs without tags";或者.gitlab-ci.yml中的job指定tag。

3. Peer's Certificate issuer is not recognized.

報錯信息:fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.x.com/root/cmop.git/': Peer's Certificate issuer is not recognized.

原因:gitlab-runner拉取代碼時,使用https協議訪問gitlab,需要驗證。

解決方案

# 參考:https://www.jianshu.com/p/fa71d97dcde0
# 因runner運行時的執行者是gitlab-runner賬戶,需要在gitlab-runner賬號下設置訪問https類網站時,免驗證
[root@gitlab-runner ~]# su - gitlab-runner
[gitlab-runner@gitlab-runner ~]$ git config --global http."sslVerify" false

# 查看
[gitlab-runner@gitlab-runner ~]$ cat /home/gitlab-runner/.gitconfig 
[http]
    sslVerify = false 

4. dial unix /var/run/docker.sock: connect: permission denied

報錯信息:Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.27/info: dial unix /var/run/docker.sock: connect: permission denied

原因:gitlab-runner賬號權限不足,不能訪問/var/run/docker.sock。

解決方案

# 將gitlab-runner用戶加入docker組
[root@gitlab-runner ~]# usermod -aG docker gitlab-runner

# 查看
[root@gitlab-runner ~]# groups gitlab-runner 

5. Couldn't resolve host 'gitlab.x.com'

報錯信息:fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.cmop.chinamcloud.com/root/cmop.git/': Couldn't resolve host 'gitlab.x.com'

原因:executor = "docker"時,執行環境是1個容器,由於驗證用的gitlab域名不能被dns解析,導致無法連接。

解決方案

  1. 在注冊時使用"--docker-volumes /etc/hosts:/etc/hosts",將運行gitlab-runner服務主機的hosts文件映射到執行容器內;
  2. 注冊時還可使用參數"--clone-url https://x.x.x.x",ip地址覆蓋域名,執行容器使用ip地址直接訪問gitlab。參考:https://docs.gitlab.com/runner/configuration/advanced-configuration.html#how-clone_url-works

    PS:使用ip覆蓋域名時,可能會帶來其他問題,如果使用的是自簽名的證書,需要明確ip地址是否也被自簽名的ca機構認證。

6. SSL certificate problem: unable to get local issuer certificate

報錯信息:fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@100.64.135.200/root/cmop.git/': SSL certificate problem: unable to get local issuer certificate

原因:注冊時,為使執行容器可訪問不能被dns解析的gitlab域名,使用了參數"--clone-url https://x.x.x.x"覆蓋了原域名,但ca機構(自簽名的ca證書)只對域名做了認證,導致使用ip訪問時不能認證。

解決方案:注冊時,將運行gitlab-runner服務主機的hosts映射到執行容器內,使其可通過被ca機構認證的域名訪問gitlab,而非ip地址。參考:https://gitlab.com/gitlab-org/gitlab-runner/issues/3477


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM