zoukankan      html  css  js  c++  java
  • devops基础01--gitlab

    devops

    devops基础01--gitlab - omgasw - 博客园 (cnblogs.com)

    devops基础02--jenkins - omgasw - 博客园 (cnblogs.com)

    devops基础03--sonarqube - omgasw - 博客园 (cnblogs.com)

    devops基础04--maven - omgasw - 博客园 (cnblogs.com)

    devops基础06--maven pom.xml - omgasw - 博客园 (cnblogs.com)

    devops基础05--nexus - omgasw - 博客园 (cnblogs.com)

    $

    $

    $

    Git 是一个开源的分布式版本控制系统

    Iterate faster, innovate together | GitLab

    Git 教程 | 菜鸟教程 (runoob.com)

    gitlab

    1.gitlab install

    1.通过yum安装

    使用清华大学源安装

    gitlab-ce | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

    cat <<EOF>> /etc/yum.repos.d/gitlab-ce.repo
    [gitlab-ce]
    name=Gitlab CE Repository
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
    gpgcheck=0
    enabled=1
    EOF
    
    sudo yum makecache
    sudo yum -y install gitlab-ce

    2.通过rpm安装包

    下载需要的安装包

    Index of /gitlab-ce/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

    rpm -ivh gitlab-ce-13.7.6-ce.0.el7.x86_64.rpm

    可能需要解决安装依赖

     Package                                    Arch                       Version                         Repository                Size
    ======================================================================================================================================
    Installing:
     policycoreutils-python                     x86_64                     2.5-34.el7                      base                     457 k
    Installing for dependencies:
     audit-libs-python                          x86_64                     2.8.5-4.el7                     base                      76 k
     checkpolicy                                x86_64                     2.5-8.el7                       base                     295 k
     libcgroup                                  x86_64                     0.41-21.el7                     base                      66 k
     libsemanage-python                         x86_64                     2.5-14.el7                      base                     113 k
     python-IPy                                 noarch                     0.75-6.el7                      base                      32 k
     setools-libs                               x86_64                     3.3.8-4.el7                     base                     620 k

    3.修改配置文件

    It looks like GitLab has not been configured yet; skipping the upgrade script.
    
           *.                  *.
          ***                 ***
         *****               *****
        .******             *******
        ********            ********
       ,,,,,,,,,***********,,,,,,,,,
      ,,,,,,,,,,,*********,,,,,,,,,,,
      .,,,,,,,,,,,*******,,,,,,,,,,,,
          ,,,,,,,,,*****,,,,,,,,,.
             ,,,,,,,****,,,,,,
                .,,,***,,,,
                    ,*,.
      
    
    
         _______ __  __          __
        / ____(_) /_/ /   ____ _/ /_
       / / __/ / __/ /   / __ `/ __ 
      / /_/ / / /_/ /___/ /_/ / /_/ /
      \____/_/\__/_____/\__,_/_.___/
      
    
    Thank you for installing GitLab!
    GitLab was unable to detect a valid hostname for your instance.
    Please configure a URL for your GitLab instance by setting `external_url`
    configuration in /etc/gitlab/gitlab.rb file.
    Then, you can start your GitLab instance by running the following command:
      sudo gitlab-ctl reconfigure

    安装完成按照指示修改配置文件

    # 修改默认的配置文件
    vim /etc/gitlab/gitlab.rb
    grep "^[a-Z]" /etc/gitlab/gitlab.rb
    
    # 配置访问地址
    external_url 'http://10.1.10.71'  # 这里一定要加上http://
    
    # 配置邮件服
    #(此处为引用https:
    //www.cnblogs.com/hgzero/p/14088215.html) gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.qq.com" gitlab_rails['smtp_port'] = 25 gitlab_rails['smtp_user_name'] = "hgzerowzh@qq.com" # 自己的qq邮箱账号 gitlab_rails['smtp_password'] = "xxx" # 开通smtp时返回的授权码 gitlab_rails['smtp_domain'] = "qq.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = false gitlab_rails['gitlab_email_from'] = "hgzerowzh@qq.com" # 指定发送邮件的邮箱地址 user["git_user_email"] = "shit@qq.com" # 指定接收邮件的邮箱地址 # 配置默认仓库存储路径 git_data_dirs({ "default" => { "path" => "/mnt/nfs-01/git-data" # 指定需要修改的路径 } })

    4.重载配置

    gitlab-ctl reconfigure # 重载配置文件

    2.编译安装git

    Git - 安装 Git (git-scm.com)

    ## centos通过yum无法安装git的新版本

    环境:

    [root@git02 ~]# cat /etc/redhat-release
    CentOS Linux release 7.8.2003 (Core)

    安装包下载:

    Index of /pub/software/scm/git/ (kernel.org)

    yum -y install zlib-devel
    yum -y install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
    yum -y install curl-devel
    wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
    tar zxvf git-2.9.5.tar.gz
    cd git-2.9.5/
    make configure
    ./configure --prefix=/usr
    make
    make install

    问题:

    报错1:
    [root@git02 git-2.9.5]# make
    GIT_VERSION = 2.9.5
        * new build flags
        CC credential-store.o
    In file included from credential-store.c:1:0:
    cache.h:40:18: fatal error: zlib.h: No such file or directory
     #include <zlib.h>
                      ^
    compilation terminated.
    make: *** [credential-store.o] Error 1
    
    解决1:
    yum -y install zlib-devel
    报错2:
    /usr/bin/perl Makefile.PL PREFIX='/usr/local' INSTALL_BASE='' --localedir='/usr/local/share/locale'
    Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 3.
    BEGIN failed--compilation aborted at Makefile.PL line 3.
    make[1]: *** [perl.mak] Error 2
    make: *** [perl/perl.mak] Error 2
    
    解决2:
    yum -y install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
    报错3:
    [root@git02 ~]# git clone http://10.1.10.71/web01/web01_01.git
    Cloning into 'web01_01'...
    fatal: Unable to find remote helper for 'http'
    
    解决3:
    yum -y install curl-devel

    卸载:

    Linux源码编译安装和卸载 - joeshang - 博客园 (cnblogs.com)

    3.常用命令

    # 查看gitlab版本
    [root@gitlab01 web01_01]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
    14.1.0[root@gitlab01 web01_01]# rpm -qa gitlab
    [root@gitlab01 web01_01]# rpm -qa |grep gitlab
    gitlab-ce-14.1.0-ce.0.el7.x86_64
    
    # 查看git版本
    [root@gitlab01 web01_01]# git --version
    git version 2.22.5
    MasonJo@DESKTOP-K95VG68 MINGW64 /d/web01_01 (main)
    $ git --version
    git version 2.28.0.windows.1
    #(此处为引用https://www.cnblogs.com/hgzero/p/14088215.html)
    gitlab-ctl start         # 启动所有 gitlab 组件
    gitlab-ctl stop          # 停止所有 gitlab 组件
    gitlab-ctl restart       # 重启所有 gitlab 组件
    gitlab-ctl status        # 查看服务状态
    
    gitlab-ctl reconfigure   # 启动服务
    gitlab-ctl show-config   # 验证配置文件
    
    gitlab-ctl tail          # 查看日志
    
    gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab

    4.用户管理

    GROUPS

    对应生产环境的项目

    PROJECTS

    对应服务,每个GROUPS可以包含多个PROJECTS

    USERS

    用户

    5.代码拉取和提交

    git pull        ## 拉取最新代码
    git add ./        ## 提交当前文件夹下所有文件到缓存区
    git commit -m 'v1'        ## 提交到本地仓库
    git push        ## 提交到gitlab仓库

    ## 开发者不允许直接向main分支提交代码

    报错:

    MasonJo@DESKTOP-K95VG68 MINGW64 /d/web01_01 (master)
    $ git push
    Enumerating objects: 6, done.
    Counting objects: 100% (6/6), done.
    Delta compression using up to 12 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (6/6), 403 bytes | 403.00 KiB/s, done.
    Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
    remote: GitLab:
    remote: A default branch (e.g. master) does not yet exist for web01/web01_01
    remote: Ask a project Owner or Maintainer to create a default branch:
    remote:
    remote: http://10.1.10.71/web01/web01_01/-/project_members
    remote:
    To http://10.1.10.71/web01/web01_01.git
    ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'http://10.1.10.71/web01/web01_01.git'

    报错:

    fatal: The current branch main has no upstream branch.
    To push the current branch and set the remote as upstream, use

    报错:

    MasonJo@DESKTOP-K95VG68 MINGW64 /d/web01_01 (main)
    $ git push
    fatal: The current branch main has no upstream branch.
    To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main


    MasonJo@DESKTOP-K95VG68 MINGW64 /d/web01_01 (main)
    $ git push --set-upstream origin main
    To http://10.1.10.71/web01/web01_01.git
    ! [rejected] main -> main (fetch first)
    error: failed to push some refs to 'http://10.1.10.71/web01/web01_01.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

    6.版本回滚

    git reset --hard HEAD^        ## 回退到上一个版本
    git reset --hard HEAD^^        ## 回退到上两个版本
    git reset --hard HEAD^^^        ## 回退到上三个版本
    
    git log        ## 查看版本信息
    git reflog        ## 查看版本简要信息,获取每次提交的ID
    
    git reset --hard d86e03f        ## 回退到指定版本

    7.分支管理

    git checkout -b test01        ## 创建并切换分支
    git checkout test01        ## 切换分支
    git branch -D test01        ## 删除分支
    gitlab新建项目如何创建 添加master develop分支    ## 新项目创建main分支
    如何删除gitlab上默认受保护的master主分支    ## 删除默认受保护分支


    git branch --set-upstream-to=origin/test01 test01    
    ## 同步本地个gitlab分支

    MasonJo@DESKTOP-K95VG68 MINGW64 /d/web01_01 (test01)
    $ git pull
    From http://10.1.10.71/web01/web01_01
     * [new branch]      test01     -> origin/test01
    There is no tracking information for the current branch.
    Please specify which branch you want to merge with.
    See git-pull(1) for details.
    
        git pull <remote> <branch>
    
    If you wish to set tracking information for this branch you can do so with:
    
        git branch --set-upstream-to=origin/<branch> test01
    
    
    MasonJo@DESKTOP-K95VG68 MINGW64 /d/web01_01 (test01)
    $  git branch --set-upstream-to=origin/test01 test01
    Branch 'test01' set up to track remote branch 'test01' from 'origin'.
    
    MasonJo@DESKTOP-K95VG68 MINGW64 /d/web01_01 (test01)
    $ git pull
    Already up to date.

    git merge origin/test01    ## 合并分支

    Gitlab的安装及使用 - Praywu - 博客园 (cnblogs.com)    ## web端请求合并分支 

    报错1:
    [root@gitlab01 web01_01]# git checkout test01
    error: Your local changes to the following files would be overwritten by checkout:
        index.html
    Please commit your changes or stash them before you switch branches.
    Aborting
    
    解决1:
    https://blog.csdn.net/qq_32452623/article/details/75645578

    8.数据备份恢复

    gitlab 备份与恢复 - LiShiChao - 博客园 (cnblogs.com)

    新版本下使用gitlab-rake进行备份和恢复_知行合一 止于至善-CSDN博客

    more references

    Gitlab的安装及使用 - Praywu - 博客园 (cnblogs.com)

  • 相关阅读:
    [Linux/wine.笔记]关于WINE(Linux上运行Windows程序的兼容层)
    [docker.笔记]常用命令
    [技巧.DotNet]超级好用的动态对象ExpandoObject
    .net core 的窗体设计器进展(.NET Core Windows Forms designer),5月中旬或将发布成熟版!
    [问题记录.Oracle/odp.net]托管ODP中,连接池的连接验证参数(validate connection=true)无效?
    [JWT]Json Web Token 备忘
    [MQ]RabbitMQ的概要介绍及消息路由规则
    常见排序算法
    C语言数值存储溢出探讨
    从计算理解数组
  • 原文地址:https://www.cnblogs.com/omgasw/p/15071706.html
Copyright © 2011-2022 走看看