zoukankan      html  css  js  c++  java
  • gitlab-ci部署实现持续集成(centos7)

    一、gitlab安装

    1. 环境准备

    // selinux和 firewall 关闭

    $ setenforce 0

    $ sed -i "/^SELINUX/s/enforcing/disabled/" /etc/selinux/config

    $ systemctl stop firewalld

    $ systemctl disable firewalld

    2. 离线安装

    $ wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-12.10.0-ce.0.el7.x86_64.rpm/download.rpm

    $ EXTERNAL_URL="http://xxxxxxx" yum -y install gitlab-ce-12.10.0-ce.0.el7.x86_64.rpm  # EXTERNAL_URL为设置gitlab的访问网址

    3、更改 EXTERNAL_URL

    $ vim /etc/gitlab/gitlab.rb

      external_url 'https://xxxxx'

    $ gitlab-ctl reconfigure   #重新应用配置

    二、Runner安装

    1、centos安装runner:

      1)下载:https://gitlab-runner-downloads.s3.amazonaws.com/latest/index.html

      2)不作为服务安装:yum -y install gitlab-runner_amd64.rpm

      3)作为服务安装:gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner

      4)启动服务:gitlab-runner start

    2、docker安装runner:

      1)安装docker:

        $ curl -L --output /etc/yum.repos.d/docker-ce.repo   https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

        $ yum -y install docker-ce

        $ mkdir /etc/docker

        $ tee /etc/docker/daemon.json <<-'EOF' {"registry-mirrors": ["https://g9ppwtqr.mirror.aliyuncs.com"] } EOF

        $ systemctl start docker && systemctl enable docker

      2)启动docker镜像的gitlab-runner:

        $ docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /data/etc/gitlab-runner:/etc/gitlab-runner gitlab/gitlab-runner:latest

        $ docker logs gitlab-runner  # 读取docker日志

    三、Runner注册

    1、注册一个全局 Runner

      //使用主机方式注册(也可以使用docker注册,详情见下)

        $  注册:gitlab-runner register
          Runtime platform arch=amd64 os=linux pid=23268 revision=c553af1a version=12.10.0
          Running in system-mode.

          Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
          https://xxxx          # 写入gitlab的地址
          Please enter the gitlab-ci token for this runner:
          zsy4iJK4-hPh8KctpVkM    # 写入全局的token 
          Please enter the gitlab-ci description for this runner:
          [c720133.xiodi.cn]:       # 写入概runner的描述
          Please enter the gitlab-ci tags for this runner (comma separated):
          host20133,host-shell     # 写入使用标签
          Registering runner... succeeded runner=zsy4iJK4
          Please enter the executor: virtualbox, docker+machine, docker-ssh, docker, parallels, shell, ssh, docker-ssh+machine, kubernetes, custom:
          shell            # 写入使用执行器
          Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

                  

    2、注册一个用户组 Runner

      //使用 docker 方式注册(也可以使用主机注册,详情见上)

        $ 启动docker:docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /data/etc/gitlab-runner:/etc/gitlab-runner gitlab/gitlab-runner:latest

        $ 进入docker:docker exec -it gitlab-runner /bin/bash

        $ 注册:gitlab-runner register      

          Runtime platform arch=amd64 os=linux pid=32 revision=c553af1a version=12.10.0
          Running in system-mode.

          Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
          https://xxxx          # 写入gitlab的地址
          Please enter the gitlab-ci token for this runner:
          Zz6yDBiRYLzdEBaHZL           # 写入全局的token 
          Please enter the gitlab-ci description for this runner:
          [dfa0f083e588]: host20133-docker-gitlab-runner    # 写入概runner的描述
          Please enter the gitlab-ci tags for this runner (comma separated):
          group-host20133-docker,docker     # 写入使用标签
          Registering runner... succeeded runner=Zz6yDBiR
          Please enter the executor: shell, ssh, virtualbox, docker-ssh+machine, docker+machine, kubernetes, custom, docker, docker-ssh, parallels:
          docker          # 写入使用执行器
          Please enter the default Docker image (e.g. ruby:2.6):

          harbor.xiodi.cn/tools/alpine:3.11    #写入默认镜像
          Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

          

    3、注册一个项目 Runner

      //(可使用 docker 方式注册,也可以使用主机注册,详情见上)

        $ 启动docker:docker run -d --name gitlab-runner2 --restart always -v /data/etc/gitlab-runner2:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest

        $ 注册:gitlab-runner register

         

    三、Runner常用命令

    1、查看可使用命令:gitlab-runner --help

    2、查看子命令使用:gitlab-runner <command> --help

    3、注册:gitlab-runner register

    4、列出配置文件中的所有runner:gitlab-runner list

    5、验证是否被 GitLab 使用:gitlab-runner verify  

    6、注销特定的 Runner:gitlab-runner unregister

    7、服务安装:gitlab-runner install

    8、服务卸载:gitlab-runner uninstall

    9、服务启动-:gitlab-runner start

    10、服务停止:gitlab-runner stop 

    11、服务重启:gitlab-runner restart

    12、服务状态:gitlab-runner status

    13、从GitLab下载工件档案:gitlab-runner artifacts-downloader

    14、将工件档案上传到GitLab:gitlab-runner artifacts-uploader

    15、创建缓存存档,将其存储在本地或将其上传到外部服务器:gitlab-runner cache-archiver

    16、从本地或外部存储的文件还原缓存档案:gitlab-runner cache-extractor

    四、gitlab-runner配置参数详解

    https://www.cnblogs.com/wu-wu/p/13269950.html

    五、代码构建

    https://www.cnblogs.com/wu-wu/p/13276400.html

  • 相关阅读:
    4.2说说计算机中的异常
    1.1组合电路、时序电路在计算机课程中的地位
    EFM32JG系列MCU内部温度传感器使用方法
    +7虚拟内存的作用,通过什么方式提高虚拟内存的性能
    +6存储结构是怎样提高性能的,它和局部性的关系是什么。
    +5性能分析定律
    +4 高速缓存
    +3软件优化至关重要,软件优化一般有哪些方法?
    +2流水线是怎样提高性能的,会遇到什么问题,解决方法是什么
    +1阿姆达尔定律
  • 原文地址:https://www.cnblogs.com/wu-wu/p/13269617.html
Copyright © 2011-2022 走看看