如何在Anolis 8 安装 极狐GitLab Runner

GitLab 是一个全球知名的一体化 DevOps 平台,很多人都通过私有化部署 GitLab 来进行源代码托管。极狐GitLab 是 GitLab 在中国的发行版,专门为中国程序员服务。可以一键式部署极狐GitLab。

基于 Anolis 龙蜥 8 和 极狐GitLab 官方仓库脚本 安装/配置 极狐GitLab Runner

说明

  1. 我们先了解在龙蜥 Anolis 8 中安装 极狐GitLab]

安装

  1. 尝试获取结果

    # 使用 curl 需要在请求头中添加标识 User-Agent
    sudo curl 'https://packages.gitlab.com/install/repositories/runner/gitlab-runner/config_file.repo?os=centos&dist=8&source=script' --header 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
    
  2. yum源下载到 /etc/yum.repos.d/runner_gitlab-runner.repo

    # 使用 curl 需要在请求头中添加标识 User-Agent
    sudo curl 'https://packages.gitlab.com/install/repositories/runner/gitlab-runner/config_file.repo?os=centos&dist=8&source=script' --header 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36' > /etc/yum.repos.d/runner_gitlab-runner.repo
    
  3. 更新yum源(首次更新,可能会提示需要下载并导入 gpgkey)

    # 更新yum源
    yum makecache
    # yum makecache -y
    
    # 清空yum源后再更新yum源
    # yum clean all && yum makecache
    # yum clean all && yum makecache -y
    
    # 更新命令及结果,为了方便,使用了 -y 进行确定
    
    [root@alios8 ~]# yum makecache -y
    AnolisOS-8 - AppStream                                                                                                     5.5 MB/s |  10 MB     00:01    
    AnolisOS-8 - BaseOS                                                                                                        4.4 MB/s | 7.9 MB     00:01    
    AnolisOS-8 - PowerTools                                                                                                    4.8 MB/s | 2.1 MB     00:00    
    runner_gitlab-runner                                                                                                       138  B/s | 862  B     00:06    
    runner_gitlab-runner                                                                                                       1.1 kB/s | 3.1 kB     00:02    
    Importing GPG key 0x51312F3F:
     Userid     : "GitLab B.V. (package repository signing key) <[email protected]>"
     Fingerprint: F640 3F65 44A3 8863 DAA0 B6E0 3F01 618A 5131 2F3F
     From       : https://packages.gitlab.com/runner/gitlab-runner/gpgkey
    runner_gitlab-runner                                                                                                       966  B/s | 3.1 kB     00:03    
    Importing GPG key 0x35DFA027:
     Userid     : "GitLab, Inc. <[email protected]>"
     Fingerprint: 09E5 7083 F34C CA94 D541 BC58 A674 BF81 35DF A027
     From       : https://packages.gitlab.com/runner/gitlab-runner/gpgkey/runner-gitlab-runner-4C80FB51394521E9.pub.gpg
    runner_gitlab-runner                                                                                                       1.0 kB/s |  12 kB     00:11    
    runner_gitlab-runner-source                                                                                                 65  B/s | 862  B     00:13    
    runner_gitlab-runner-source                                                                                                773  B/s | 3.1 kB     00:04    
    Importing GPG key 0x51312F3F:
     Userid     : "GitLab B.V. (package repository signing key) <[email protected]>"
     Fingerprint: F640 3F65 44A3 8863 DAA0 B6E0 3F01 618A 5131 2F3F
     From       : https://packages.gitlab.com/runner/gitlab-runner/gpgkey
    runner_gitlab-runner-source                                                                                                1.0 kB/s | 3.1 kB     00:03    
    Importing GPG key 0x35DFA027:
     Userid     : "GitLab, Inc. <[email protected]>"
     Fingerprint: 09E5 7083 F34C CA94 D541 BC58 A674 BF81 35DF A027
     From       : https://packages.gitlab.com/runner/gitlab-runner/gpgkey/runner-gitlab-runner-4C80FB51394521E9.pub.gpg
    runner_gitlab-runner-source                                                                                                 31  B/s | 296  B     00:09    
    Metadata cache created.
    [root@alios8 ~]# 
    
  4. 安装

    yum -y install gitlab-runner
    

配置

  1. 配置证书信任
```
# 自己生成的证书,如果不进行信任,注册时可能出现的问题:
# ERROR: Registering runner... failed                 runner=6iuLhyWx status=couldn't execute POST against https://gitlab.example.com/api/v4/runners: Post "https://gitlab.example.com/api/v4/runners": x509: certificate is not valid for any names, but wanted to match gitlab.example.com

# 下列执行时,需要本机能使用 GitLab 域名访问
# 可以修改 本机 /etc/hosts 文件解决

# 如果域名未解析,会出现
# ERROR: Registering runner... failed                 runner=z4uLTqoa status=couldn't execute POST against https://gitlab.example.com/api/v4/runners: Post "https://gitlab.example.com/api/v4/runners": dial tcp: lookup gitlab.example.com on 192.168.61.2:53: no such host

# 如果创建证书时,未设置“Common Name (e.g. server FQDN or YOUR name) []”时,会出现
# ERROR: Registering runner... failed                 runner=z4uLTqoa status=couldn't execute POST against https://gitlab.example.com/api/v4/runners: Post "https://gitlab.example.com/api/v4/runners": x509: certificate is not valid for any names, but wanted to match gitlab.example.com

# 重新设置了域名证书,需要执行 sudo gitlab-ctl restart,如果修改了 /etc/gitlab/gitlab.rb 文件,需要先执行 sudo gitlab-ctl reconfigure,再执行 sudo gitlab-ctl restart

# 生成的证书不满足GitLab Runner的检查时,会出现下列错误,请根据前面章节中的内容重新生成
# ERROR: Registering runner... failed                 runner=z4uLTqoa status=couldn't execute POST against https://gitlab.example.com/api/v4/runners: Post "https://gitlab.example.com/api/v4/runners": x509: certificate relies on legacy Common Name field, use SANs instead

# 如果域名证书未生效,或者已过期,会出现下面的错误
# x509: certificate has expired or is not yet valid: current time 2022-11-15T20:45:12+08:00 is before 2022-11-15T19:49:27Z

#
#

sudo mkdir -p /etc/gitlab-runner/certs

# 本文使用域名是IP:192.168.80.14
# 可根据自己的需要,修改下方的域名及端口

# 使用客户端下载 GitLab 实例的证书
openssl s_client -showcerts -connect 192.168.80.14:443 -servername 192.168.80.14 < /dev/null 2>/dev/null | openssl x509 -outform PEM > /etc/gitlab-runner/certs/192.168.80.14.crt
# openssl s_client -showcerts -connect gitlab.example.com:443 -servername gitlab.example.com < /dev/null 2>/dev/null | openssl x509 -outform PEM > /etc/gitlab-runner/certs/gitlab.example.com.crt

# 验证文件是否已正确安装
echo | openssl s_client -CAfile /etc/gitlab-runner/certs/192.168.80.14.crt -connect 192.168.80.14:443 -servername 192.168.80.14
# echo | openssl s_client -CAfile /etc/gitlab-runner/certs/gitlab.example.com.crt -connect gitlab.example.com:443 -servername gitlab.example.com
```
  1. 注册 极狐GitLab Runner

    gitlab-runner register
    
  2. 提示:Enter the GitLab instance URL:

    输入极狐GitLab 的地址

    https://192.168.80.14
    # https://gitlab.example.com/
    
  3. 提示:Enter the registration token:

    # 复制 https://192.168.80.14/admin/runners 页面中的 token(点击:注册一个Runner即可获取)
    # 复制 https://gitlab.example.com/admin/runners 页面中的 token(点击:注册一个Runner即可获取)
    6iuLhyWxqypcyaNtUG_C
    
  4. 提示:Enter a description for the runner:

    输入流水线的名称,默认为 CentOS 主机名

  5. 提示:Enter tags for the runner (comma-separated):

    输入流水线的标签名(非Git仓库的标签),即:.gitlab-ci.yml 文件中标签,可为空,**为空时允许所有未指定标签的流水线使用,可在GitLab页面中进行随时调整 **

  6. 提示:Enter optional maintenance note for the runner:

    输入流水线的描述,可为空

  7. 提示:Registering runner... succeeded runner=6iuLhyWx
    Enter an executor: docker, docker-ssh, parallels, shell, docker-ssh+machine, instance, kubernetes, custom, ssh, virtualbox, docker+machine:

    选择流水线执行器

    # 输入 docker,用于后面的 GitLab Pages 做准备
    docker
    
  8. 提示:Enter the default Docker image (for example, ruby:2.7):

    输入默认docker镜像

  9. 出现下列语句,说明流水线已注册成功: /etc/gitlab-runner/config.toml 是GitLab Runner配置文件的位置

    Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
     
    Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml" 
    
  10. 修改流水线配置,使其同时可以执行多个任务

    vim /etc/gitlab-runner/config.toml
    
    # 同一时间支持运行的最大任务数
    concurrent = 10
    
  11. 在以下地址中可看到流水线的状态

    1. <h ttps://gitlab .example. com/admin/runners>
    2. <h ttps://192.168.61.129/admin/runners>
  12. 列出所有

    gitlab-runner list
    
  13. 查看状态

    gitlab-runner status
    
  14. 停止

    gitlab-runner stop
    
  15. 启动

    gitlab-runner start
    

更多关于极狐GitLab 的最佳实践,请搜索关注【极狐GitLab】公众号或者登录极狐GitLab 官网 进行学习。

热门相关:18岁性感女王的性丑闻   街头悍将粤语   人道主义吸血鬼在寻找自杀自愿者   女士邀请函3   美味世子三姐妹