GitLab环境搭建

文章目录


前言

之前搭建的版本比较旧,目前官网的支持文档已经不支持先前搭建的版本! 同时也是为了了解新版本的新功能,同时从零开始系统性学习!

下面是文章正文,希望能帮到您

一、GitLab是什么?

GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的Web服务。

二、安装步骤

1.环境准备

系统准备:
Temp-192.168.1.78

软件包准备:
准备下载新版本的社区版
https://about.gitlab.com/install/#centos-7

这里面有ee版本和ce版本的区别
https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh
这里只研究ce(社区版)的
https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh

安装前的系统检查以及配置脚本,这种方式针对可以访问公网地址可以通过脚本链接处理一些必要依赖等:

#!/bin/bash

unknown_os ()
{
  echo "Unfortunately, your operating system distribution and version are not supported by this script."
  echo
  echo "You can override the OS detection by setting os= and dist= prior to running this script."
  echo "You can find a list of supported OSes and distributions on our website: https://packages.gitlab.com/docs#os_distro_version"
  echo
  echo "For example, to force CentOS 6: os=el dist=6 ./script.sh"
  echo
  echo "Please email support@packagecloud.io and let us know if you run into any issues."
  exit 1
}

curl_check ()
{
  echo "Checking for curl..."
  if command -v curl > /dev/null; then
    echo "Detected curl..."
  else
    echo "Installing curl..."
    yum install -d0 -e0 -y curl
  fi
}


detect_os ()
{
  if [[ ( -z "${os}" ) && ( -z "${dist}" ) ]]; then
    if [ -e /etc/os-release ]; then
      . /etc/os-release
      os=${ID}
      if [ "${os}" = "poky" ]; then
        dist=`echo ${VERSION_ID}`
      elif [ "${os}" = "sles" ]; then
        dist=`echo ${VERSION_ID}`
      elif [ "${os}" = "opensuse" ]; then
        dist=`echo ${VERSION_ID}`
      elif [ "${os}" = "opensuse-leap" ]; then
        os=opensuse
        dist=`echo ${VERSION_ID}`
      else
        dist=`echo ${VERSION_ID} | awk -F '.' '{ print $1 }'`
      fi

    elif [ `which lsb_release 2>/dev/null` ]; then
      # get major version (e.g. '5' or '6')
      dist=`lsb_release -r | cut -f2 | awk -F '.' '{ print $1 }'`

      # get os (e.g. 'centos', 'redhatenterpriseserver', etc)
      os=`lsb_release -i | cut -f2 | awk '{ print tolower($1) }'`

    elif [ -e /etc/oracle-release ]; then
      dist=`cut -f5 --delimiter=' ' /etc/oracle-release | awk -F '.' '{ print $1 }'`
      os='ol'

    elif [ -e /etc/fedora-release ]; then
      dist=`cut -f3 --delimiter=' ' /etc/fedora-release`
      os='fedora'

    elif [ -e /etc/redhat-release ]; then
      os_hint=`cat /etc/redhat-release  | awk '{ print tolower($1) }'`
      if [ "${os_hint}" = "centos" ]; then
        dist=`cat /etc/redhat-release | awk '{ print $3 }' | awk -F '.' '{ print $1 }'`
        os='centos'
      elif [ "${os_hint}" = "scientific" ]; then
        dist=`cat /etc/redhat-release | awk '{ print $4 }' | awk -F '.' '{ print $1 }'`
        os='scientific'
      else
        dist=`cat /etc/redhat-release  | awk '{ print tolower($7) }' | cut -f1 --delimiter='.'`
        os='redhatenterpriseserver'
      fi

    else
      aws=`grep -q Amazon /etc/issue`
      if [ "$?" = "0" ]; then
        dist='6'
        os='aws'
      else
        unknown_os
      fi
    fi
  fi

  if [[ ( -z "${os}" ) || ( -z "${dist}" ) ]]; then
    unknown_os
  fi

  # remove whitespace from OS and dist name
  os="${os// /}"
  dist="${dist// /}"

  echo "Detected operating system as ${os}/${dist}."

  if [ "${dist}" = "8" ]; then
    _skip_pygpgme=1
  else
    _skip_pygpgme=0
  fi
}

finalize_yum_repo ()
{
  if [ "$_skip_pygpgme" = 0 ]; then
    echo "Installing pygpgme to verify GPG signatures..."
    yum install -y pygpgme --disablerepo='gitlab_gitlab-ce'
    pypgpme_check=`rpm -qa | grep -qw pygpgme`
    if [ "$?" != "0" ]; then
      echo
      echo "WARNING: "
      echo "The pygpgme package could not be installed. This means GPG verification is not possible for any RPM installed on your system. "
      echo "To fix this, add a repository with pygpgme. Usualy, the EPEL repository for your system will have this. "
      echo "More information: https://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3F"
      echo

      # set the repo_gpgcheck option to 0
      sed -i'' 's/repo_gpgcheck=1/repo_gpgcheck=0/' /etc/yum.repos.d/gitlab_gitlab-ce.repo
    fi
  fi

  echo "Installing yum-utils..."
  yum install -y yum-utils --disablerepo='gitlab_gitlab-ce'
  yum_utils_check=`rpm -qa | grep -qw yum-utils`
  if [ "$?" != "0" ]; then
    echo
    echo "WARNING: "
    echo "The yum-utils package could not be installed. This means you may not be able to install source RPMs or use other yum features."
    echo
  fi

  echo "Generating yum cache for gitlab_gitlab-ce..."
  yum -q makecache -y --disablerepo='*' --enablerepo='gitlab_gitlab-ce'

  echo "Generating yum cache for gitlab_gitlab-ce-source..."
  yum -q makecache -y --disablerepo='*' --enablerepo='gitlab_gitlab-ce-source'
}

finalize_zypper_repo ()
{
  zypper --gpg-auto-import-keys refresh gitlab_gitlab-ce
  zypper --gpg-auto-import-keys refresh gitlab_gitlab-ce-source
}

main ()
{
  detect_os
  curl_check


  yum_repo_config_url="https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/config_file.repo?os=${os}&dist=${dist}&source=script"

  if [ "${os}" = "sles" ] || [ "${os}" = "opensuse" ]; then
    yum_repo_path=/etc/zypp/repos.d/gitlab_gitlab-ce.repo
  else
    yum_repo_path=/etc/yum.repos.d/gitlab_gitlab-ce.repo
  fi

  echo "Downloading repository file: ${yum_repo_config_url}"

  curl -sSf "${yum_repo_config_url}" > $yum_repo_path
  curl_exit_code=$?

  if [ "$curl_exit_code" = "22" ]; then
    echo
    echo
    echo -n "Unable to download repo config from: "
    echo "${yum_repo_config_url}"
    echo
    echo "This usually happens if your operating system is not supported by "
    echo "packagecloud.io, or this script's OS detection failed."
    echo
    echo "You can override the OS detection by setting os= and dist= prior to running this script."
    echo "You can find a list of supported OSes and distributions on our website: https://packages.gitlab.com/docs#os_distro_version"
    echo
    echo "For example, to force CentOS 6: os=el dist=6 ./script.sh"
    echo
    echo "If you are running a supported OS, please email support@packagecloud.io and report this."
    [ -e $yum_repo_path ] && rm $yum_repo_path
    exit 1
  elif [ "$curl_exit_code" = "35" -o "$curl_exit_code" = "60" ]; then
    echo
    echo "curl is unable to connect to packagecloud.io over TLS when running: "
    echo "    curl ${yum_repo_config_url}"
    echo
    echo "This is usually due to one of two things:"
    echo
    echo " 1.) Missing CA root certificates (make sure the ca-certificates package is installed)"
    echo " 2.) An old version of libssl. Try upgrading libssl on your system to a more recent version"
    echo
    echo "Contact support@packagecloud.io with information about your system for help."
    [ -e $yum_repo_path ] && rm $yum_repo_path
    exit 1
  elif [ "$curl_exit_code" -gt "0" ]; then
    echo
    echo "Unable to run: "
    echo "    curl ${yum_repo_config_url}"
    echo
    echo "Double check your curl installation and try again."
    [ -e $yum_repo_path ] && rm $yum_repo_path
    exit 1
  else
    echo "done."
  fi

  if [ "${os}" = "sles" ] || [ "${os}" = "opensuse" ]; then
    finalize_zypper_repo
  else
    finalize_yum_repo
  fi

  echo
  echo "The repository is setup! You can now install packages."
}

main

2.手动安装

GitLab Linux环境rpm包下载链接:

https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-13.10.0-ce.0.el7.x86_64.rpm
[root@jhpoc gitlab]# ls
gitlab-ce-13.10.0-ce.0.el7.x86_64.rpm
[root@jhpoc gitlab]# yum -y install ./gitlab-ce-13.10.0-ce.0.el7.x86_64.rpm 
已加载插件:fastestmirror
正在检查 ./gitlab-ce-13.10.0-ce.0.el7.x86_64.rpm: gitlab-ce-13.10.0-ce.0.el7.x86_64
./gitlab-ce-13.10.0-ce.0.el7.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 gitlab-ce.x86_64.0.13.10.0-ce.0.el7 将被 安装
--> 正在处理依赖关系 policycoreutils-python,它被软件包 gitlab-ce-13.10.0-ce.0.el7.x86_64 需要
gitlab_gitlab-ee/x86_64/signature                                                                                                 |  862 B  00:00:00     
gitlab_gitlab-ee/x86_64/signature                                                                                                 | 1.0 kB  00:00:00 !!! 
gitlab_gitlab-ee-source/signature                                                                                                 |  862 B  00:00:00     
gitlab_gitlab-ee-source/signature                                                                                                 |  951 B  00:00:00 !!! 
Loading mirror speeds from cached hostfile
 * epel: mirror.sjtu.edu.cn
 * webtatic: us-east.repo.webtatic.com
--> 正在检查事务
---> 软件包 policycoreutils-python.x86_64.0.2.5-17.1.el7 将被 安装
--> 正在处理依赖关系 setools-libs >= 3.3.8-1,它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 libsemanage-python >= 2.5-5,它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 audit-libs-python >= 2.1.3-4,它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 python-IPy,它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 libqpol.so.1(VERS_1.4)(64bit),它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 libqpol.so.1(VERS_1.2)(64bit),它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 libcgroup,它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 libapol.so.4(VERS_4.0)(64bit),它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 checkpolicy,它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 libqpol.so.1()(64bit),它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在处理依赖关系 libapol.so.4()(64bit),它被软件包 policycoreutils-python-2.5-17.1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 audit-libs-python.x86_64.0.2.7.6-3.el7 将被 安装
---> 软件包 checkpolicy.x86_64.0.2.5-4.el7 将被 安装
---> 软件包 libcgroup.x86_64.0.0.41-13.el7 将被 安装
---> 软件包 libsemanage-python.x86_64.0.2.5-8.el7 将被 安装
---> 软件包 python-IPy.noarch.0.0.75-6.el7 将被 安装
---> 软件包 setools-libs.x86_64.0.3.3.8-1.1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=========================================================================================================================================================
 Package                                架构                   版本                             源                                                  大小
=========================================================================================================================================================
正在安装:
 gitlab-ce                              x86_64                 13.10.0-ce.0.el7                 /gitlab-ce-13.10.0-ce.0.el7.x86_64                 1.8 G
为依赖而安装:
 audit-libs-python                      x86_64                 2.7.6-3.el7                      base                                                73 k
 checkpolicy                            x86_64                 2.5-4.el7                        base                                               290 k
 libcgroup                              x86_64                 0.41-13.el7                      base                                                65 k
 libsemanage-python                     x86_64                 2.5-8.el7                        base                                               104 k
 policycoreutils-python                 x86_64                 2.5-17.1.el7                     base                                               446 k
 python-IPy                             noarch                 0.75-6.el7                       base                                                32 k
 setools-libs                           x86_64                 3.3.8-1.1.el7                    base                                               612 k

事务概要
=========================================================================================================================================================
安装  1 软件包 (+7 依赖软件包)

总计:1.8 G
安装大小:1.8 G
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : setools-libs-3.3.8-1.1.el7.x86_64                                                                                                    1/8 
  正在安装    : checkpolicy-2.5-4.el7.x86_64                                                                                                         2/8 
  正在安装    : libcgroup-0.41-13.el7.x86_64                                                                                                         3/8 
  正在安装    : python-IPy-0.75-6.el7.noarch                                                                                                         4/8 
  正在安装    : audit-libs-python-2.7.6-3.el7.x86_64                                                                                                 5/8 
  正在安装    : libsemanage-python-2.5-8.el7.x86_64                                                                                                  6/8 
  正在安装    : policycoreutils-python-2.5-17.1.el7.x86_64                                                                                           7/8 
  正在安装    : gitlab-ce-13.10.0-ce.0.el7.x86_64                                                                                                    8/8 
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

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=13-10

  验证中      : libsemanage-python-2.5-8.el7.x86_64                                                                                                  1/8 
  验证中      : audit-libs-python-2.7.6-3.el7.x86_64                                                                                                 2/8 
  验证中      : python-IPy-0.75-6.el7.noarch                                                                                                         3/8 
  验证中      : policycoreutils-python-2.5-17.1.el7.x86_64                                                                                           4/8 
  验证中      : gitlab-ce-13.10.0-ce.0.el7.x86_64                                                                                                    5/8 
  验证中      : libcgroup-0.41-13.el7.x86_64                                                                                                         6/8 
  验证中      : checkpolicy-2.5-4.el7.x86_64                                                                                                         7/8 
  验证中      : setools-libs-3.3.8-1.1.el7.x86_64                                                                                                    8/8 

已安装:
  gitlab-ce.x86_64 0:13.10.0-ce.0.el7                                                                                                                    

作为依赖被安装:
  audit-libs-python.x86_64 0:2.7.6-3.el7       checkpolicy.x86_64 0:2.5-4.el7 libcgroup.x86_64 0:0.41-13.el7      libsemanage-python.x86_64 0:2.5-8.el7
  policycoreutils-python.x86_64 0:2.5-17.1.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-1.1.el7

完毕!

3.配置启动

[root@jhpoc gitlab]#
主要的配置文件:
/etc/gitlab/gitlab.rb
/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yaml
需要先执行初始化配置:
gitlab-ctl reconfigure
如果后续配置需要修改:
gitlab-ctl restart
登陆地址:
http://192.168.1.78/


总结

GitLab服务的安装是第一步。接下来主要就是基于自己工作的角色去有针对性的学习!研发人员需要关注代码提交、分支管理等的常用操作并理解其具体含义以及操作的风险等!系统管理员需要保障服务的正常运行,权限管理、文件备份等操作。

上一篇:2022-2023年英语周报七年级第31期答案汇总


下一篇:Coin Change(C++零钱兑换)