1. 程式人生 > 其它 >gitlab Runner 安裝與部署

gitlab Runner 安裝與部署

1、安裝gitlab Runner

本次演示為centos 7.5環境,請各位按照自己環境調整

1)線上安裝

#安裝官方映象源

[root@k8s-node02 ~]# curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash

#yum 安裝gitlab Runner

[root@k8s-node02 ~]# yum install gitlab-runner -y

2)離線安裝

  • gitlab Runner下載地址:https://packages.gitlab.com/runner/gitlab-runner
  • 伺服器建立安裝包位置

    [root@k8s-node02 gitlab-runner]# mkdir -p /tools
  • 下載gitlab-runner
    [root@k8s-node02 gitlab-runner]# cd /tools/
    [root@k8s-node02 tools]# ll
    total 0
    [root@k8s-node02 tools]# wget https://packages.gitlab.com/runner/gitlab-runner/packages/fedora/29/gitlab-runner-12.6.0-1.x86_64.rpm/download.rpm
    [root@k8s-node02 tools]# ll
    total 49860
    -rw-r--r-- 1 root root 51052604 Jan 19 22:45 gitlab-runner-12.6.0-1.x86_64.rpm
  • 安裝gitlab runner

    #安裝git
    [root@k8s-node02 tools]# yum install git -y
    
    #rpm離線安裝gitlab runner,需要依賴git,所以請提前安裝git
    [root@k8s-node02 tools]# rpm -ivh gitlab-runner-12.6.0-1.x86_64.rpm 
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:gitlab-runner-12.6.0-1           ################################# [100%]
  • 提示:以上兩種安裝,請各位安裝實際情況安裝
  • 指定gitlab-runner
    [root@k8s-node02 ~]# useradd staff
    
    [root@k8s-node02 ~]# gitlab-runner uninstall 
    Runtime platform                                    arch=amd64 os=linux pid=25137 revision=ac8e767a version=12.6.0
    
    [root@k8s-node02 ~]# gitlab-runner install --working-directory /home/staff --user staff
    Runtime platform                                    arch=amd64 os=linux pid=25169 revision=ac8e767a version=12.6.0
    
    [root@k8s-node02 staff]# vim /etc/systemd/system/gitlab-runner.service
    [root@k8s-node02 staff]# cat /etc/systemd/system/gitlab-runner.service
    [Unit]
    Description=GitLab Runner
    After=syslog.target network.target
    ConditionFileIsExecutable=/usr/lib/gitlab-runner/gitlab-runner
    
    [Service]
    StartLimitInterval=5
    StartLimitBurst=10
    ExecStart=/usr/lib/gitlab-runner/gitlab-runner "run" "--working-directory" "/home/staff" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--syslog" "--user" "staff"
    
    Restart=always
    RestartSec=120
    
    [Install]
    WantedBy=multi-user.target
  • 啟動gitlab服務
    [root@k8s-node02 ~]# systemctl  daemon-reload                            #重新載入配置
    [root@k8s-node02 tools]# /bin/systemctl start gitlab-runner                  #啟動服務
    [root@k8s-node02 tools]# /bin/systemctl enable gitlab-runner             #設定開機啟動
    [root@k8s-node02 tools]# /bin/systemctl restart gitlab-runner              #重啟服務
  • 驗證服務是否啟動
    [root@k8s-node02 java_demo]# ps -ef |grep gitlab
    root     25339     1  0 01:16 ?        00:00:11 /usr/lib/gitlab-runner/gitlab-runner run --working-directory /home/staff --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user staff
  • 設定許可權
    [root@k8s-node02 ~]# chown -R staff.staff /home/gitlab-runner

3)gitlab runner註冊服務

  • 安裝了gitlab Runner之後,就可以為gitlab中的倉庫註冊一個Runner,註冊的互動式命令如下:

    [root@k8s-node02 ~]# gitlab-runner register
  • 我們開始註冊
    [root@k8s-node02 ~]# gitlab-runner register
    Runtime platform                                    arch=amd64 os=linux pid=6245 revision=ac8e767a version=12.6.0
    Running in system-mode.                            
    
    #輸入公司的gitlab公網地址                                                   
    Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
    http://192.168.200.133/
    
    #輸入gitlab的token,找到第三步token,然後選擇第四步,複製token
    Please enter the gitlab-ci token for this runner:
    8sjydnrsPuSRhKiQTQky
    
    #輸入描述這個runner名稱
    Please enter the gitlab-ci description for this runner:
    [k8s-node02]: my-runner
    
    #輸入runner的標籤
    Please enter the gitlab-ci tags for this runner (comma separated):
    my-tag,another-tag
    Registering runner... succeeded                     runner=8sjydnrs
    
    #輸入runner執行器的環境
    Please enter the executor: custom, docker-ssh, parallels, kubernetes, docker-ssh+machine, docker, shell, ssh, virtualbox, docker+machine:
    shell
    Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 
  • 驗證gitlab runner是否註冊成功

在驗證的時候,請重新整理介面,再次檢視,驗證
3)gitlab Runner常用命令彙總

命令

描述

gitlab-runner run

執行一個runner服務

gitlab-runner register

註冊一個新的runner

gitlab-runner start

啟動服務

gitlab-runner stop

關閉服務

gitlab-runner restart

重啟服務

gitlab-runner status

檢視各個runner的狀態

gitlab-runner unregister

登出掉某個runner

gitlab-runner list

顯示所有執行著的runner

gitlab-runner verify

檢查已註冊的執行程式是否可以連線到GitLab,但它不驗證GitLab Runner服務是否正在使用執行程式。