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

     

  • 我們開始注冊G it Lab Projects v 
Admin Area 
- Overview 
Dashboard 
Projects 
Users 
Groups 
Jobs 
Runners 
Gitaly Servers 
Groups v 
More v 
Admin Area Runners 
A 'Runner' is a process which runs ajob. You can set up as many Runners as you need. 
Runners can be placed on separate users, servers, even on your local machine. 
Each Runner can be in one of the following states and/or belong to one of the following 
Search or jump to... 
Set up a shared Runner manually 
1. Install GitLab Runner 
2. Specify the following URL during the Runner setup: http://1g2 . 168.230 .133/ 
Q 
0) 
types: 
group 
specific 
Iliéck 
- Runner runs jobs from all unassigned projects 
Runner runs jobs from all unassigned projects in its group 
- Runner runs jobs from assigned projects 
Runner cannot be assigned to other projects 
Runner will not receive any new jobs 
f] Runners 
Recent searches v 
Search or filter results... 
Reset runners registration token 
4. Start the Runner! 
Created date 
token 
Runners currently online: O
    [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是否注冊成功G it Lab Projects v 
Admin Area 
- Overview 
Dashboard 
Projects 
Users 
Groups 
Jobs 
Runners 
Gitaly Servers 
Monitoring 
Messages 
System Hooks 
Groups v 
More v 
Admin Area Runners 
(settings) 
A 'Runner' is a process which runs ajob. You can set up as many Runners as you need. 
Runners can be placed on separate users, servers, even on your local machine. 
Each Runner can be in one of the following states and/or belong to one of the following 
types: 
Search or jump to... 
Set up a shared Runner manually 
1. Install GitLab Runner 
2. Specify the following URL during the Runner setup: http:1/192 . 168.230 .133/ 
3. Use the following registration token during setup: 8sjydn rspuSRhKIQTQky 
Reset runners registration token 
4. Start the Runner! 
Q 
0) 
group 
specific 
Iliéck 
- Runner runs jobs from all unassigned projects 
Runner runs jobs from all unassigned projects in its group 
- Runner runs jobs from assigned projects 
Runner cannot be assigned to other projects 
Runner will not receive any new jobs 
Recent searches v Search or filter results... 
Type/State 
shared 
Runner token 
Description 
my-runner 
Version 
12.6.o 
IP Address 
192.168.200.134 
Created date 
Projects Jabs 
n/a 
Tags 
another-tag 
my-tag 
Last contact 
in 5 hours 
Runners currently online: 1 
11

      在驗證的時候,請刷新界面,再次查看,驗證
   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服務是否正在使用運行程序。


免責聲明!

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



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