安装GItlab-Runner

发布时间 2023-03-31 17:11:24作者: edclol

安装GItlab-Runner

  1. 安装最新的Git 2.0以上版本,版本低很容易报错

    https://ius.io/setup

    yum install \
    https://repo.ius.io/ius-release-el7.rpm \
    https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y
    
    yum search git
    
    yum install git224 -y
    
    git --version
    
  2. 安装仓库源

    https://docs.gitlab.com/runner/install/linux-repository.html

    # For RHEL/CentOS/Fedora
    curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
    
  3. 安装Gitlab-Runner

    yum install gitlab-runner -y
    
  4. 查看Runner配置

    vi /etc/systemd/system/gitlab-runner.service
    
  5. 切换到Runner用户,并配置mvn等环境变量

    su - gitlab-runner
    
    vi .bash_profile
    
    # User specific environment and startup programs
    MAVEN_HOME=/opt/apache-maven-3.6.3/
    PATH=$PATH:$HOME/.local/bin:$HOME/bin:/$MAVEN_HOME/bin
    export PATH
    
    
  6. 给Runner用户增加docker权限

    1. 查询是否有docker组

      cat /etc/group | grep docker
      

      如果没有可以通过该命令添加(一般默认是有的)

      sudo groupadd docker
      
    2. 将当前用户添加到docker组

      sudo usermod -aG docker gitlab-runner
      
    3. 重启docker服务

      sudo systemctl restart docker.service
      
  7. 注册Runner为shellrunner

     gitlab-runner register
    
    [gitlab-runner@cdh-upgrade-2 ~]$ gitlab-runner register
    Runtime platform                                    arch=amd64 os=linux pid=28102 revision=7a6612da version=13.12.0
    WARNING: Running in user-mode.
    WARNING: The user-mode requires you to manually start builds processing:
    WARNING: $ gitlab-runner run
    WARNING: Use sudo for system-mode:
    WARNING: $ sudo gitlab-runner...
    Enter the GitLab instance URL (for example, https://gitlab.com/):
    http://10.30.20.182/
    Enter the registration token:
    2xZAQReuYCDwFMDYfh8c
    Enter a description for the runner:
    [cdh-upgrade-2]:
    Enter tags for the runner (comma-separated):
    
    Registering runner... succeeded                     runner=2xZAQReu
    Enter an executor: docker-ssh+machine, custom, docker-ssh, parallels, shell, virtualbox, docker+machine, docker, ssh, kubernetes:
    shell
    Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
    
  8. 查看运行状况

    # gitlab-runner status
    # gitlab-runner list
    # gitlab-runner restart
    

其他问题

Gitlab的Gravatar头像无法显示的问题

通过gitlab搭建的git仓库,由于Gravatar被墙了,导致Gravatar头像无法显示。总觉得怪怪的。

社区版gitlab解决办法:

vi /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

将plain_url改为

#plain_url:      # default: http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon
plain_url:     http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon

然后执行

gitlab-ctl restart
gitlab-rake cache:clear RAILS_ENV=production