GitHub與GitLab的區(qū)別以及GitLab的搭建與使用

前言

Git — 無需多說止吐,2018年還不知道Git的程序猿不是好程序猿

Git誕生于2005年忍啤,大神Linus的作品,Github誕生于2008年耕皮,沒有Git就沒有GitHub凯肋,Github已成為全球最大的代(tong)碼(xing)開(jiao)源(you)社(wang)區(qū)(zhan)谊惭,注冊(cè)免費(fèi)用戶即可在Github上免費(fèi)托管開源代碼,如需建立私有倉(cāng)庫(kù)必須付費(fèi)侮东。那么Gitlab又是什么圈盔?

GitLab和GitHub一樣屬于第三方基于Git開發(fā)的作品,免費(fèi)且開源(https://github.com/gitlabhq/gitlabhq 基于MIT協(xié)議)悄雅,與Github類似驱敲,可以注冊(cè)用戶,任意提交你的代碼宽闲,添加SSHKey等等众眨。不同的是,GitLab是可以部署到自己的服務(wù)器上容诬,數(shù)據(jù)庫(kù)等一切信息都掌握在自己手上娩梨,適合團(tuán)隊(duì)內(nèi)部協(xié)作開發(fā),你總不可能把團(tuán)隊(duì)內(nèi)部的智慧總放在別人的服務(wù)器上吧览徒?簡(jiǎn)單來說可把GitLab看作個(gè)人版的GitHub姚建。

搭建GitLab

環(huán)境配置
  1. 系統(tǒng):Red-Hat系列CentOS 7.x-x86_64(筆者采用的是CentOS7.2)
  2. CPU:建議雙核以上
  3. 內(nèi)存:2GB(官方建議4GB以上,請(qǐng)看下圖官方給出的建議)
GitLab官方建議配置.jpg
安裝

GitLab 10.x之后添加多了一些依賴吱殉,并且要啟動(dòng)sshd服務(wù),所以我們先添加依賴厘托,啟動(dòng)sshd友雳,為防火墻添加服務(wù)

sudo yum install -y curl policycoreutils-python openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd 
sudo firewall-cmd –permanent –add-service=http
sudo systemctl reload firewalld

GitLab官方文檔中有多種安裝方式,分別為deb铅匹,rpm押赊,node,python,gem流礁。詳情請(qǐng)看:https://packages.gitlab.com/gitlab/gitlab-ce/install

筆者采用的是rpm安裝方式涕俗,命令行下輸入

curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

然后靜靜等待完成,此時(shí)細(xì)心的同學(xué)會(huì)發(fā)現(xiàn)這是個(gè)shell神帅? 沒錯(cuò)再姑,這是官方的一個(gè)shell,有興趣的同學(xué)可以研究一下這個(gè)shell

#!/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}`
      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}."
}

finalize_yum_repo ()
{
  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

  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'
}

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

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

好了找御,完成之后輸入

yum search gitlab

可看到庫(kù)已經(jīng)添加進(jìn)來元镀,注意是上邊那個(gè),我第一次添加的時(shí)候添加錯(cuò)成ee版霎桅,尷尬臉栖疑,ee版是企業(yè)版,ce版是社區(qū)版滔驶,從這可以看到GitLab包含了 Nginx遇革,PostgreSQL數(shù)據(jù)庫(kù),還有Redis

有了這個(gè)之后就可以直接安裝啦揭糕,輸入

yum install -y gitlab

又經(jīng)歷一次靜靜的等待直到出現(xiàn)

install GitLab.jpg

此時(shí)此刻萝快,GitLab 終于裝上了! 然后按照提示 修改 /etc/gitlab/gitlab.rb 把 external_url 中的地址修改一下

修改配置地址.jpg

完成之后執(zhí)行

gitlab-ctl reconfigure

繼續(xù)靜靜地等待配置和啟動(dòng)服務(wù)完成….

終于等到完成了插佛,立馬在瀏覽器中輸入地址杠巡,結(jié)果..

服務(wù)器502.jpg

甚至出現(xiàn)無法連接服務(wù)器,這并不是我想要的結(jié)果雇寇! 于是我立馬看了下gitlab的狀態(tài)

gitlab-ctl status

發(fā)現(xiàn)并沒有什么問題啊氢拥,一切正常,這時(shí)候心中千萬只草泥馬在奔馳

查閱一番資料之后锨侯,也就是文章一開始的配置之后發(fā)現(xiàn)是因?yàn)閭€(gè)人服務(wù)器配置不夠嫩海,服務(wù)跑不起來.

最后實(shí)在不死心,跑了一趟虛擬機(jī)終于給跑起來了囚痴,至此安裝GitLab結(jié)束

使用

第一次進(jìn)入頁面的時(shí)候會(huì)提示你修改管理員密碼叁怪,按照步驟修改密碼登錄就可以了

登錄之后創(chuàng)建倉(cāng)庫(kù),可見Gitlab還可以創(chuàng)建自己的私有庫(kù)



也可像Github一樣查看哪個(gè)日期有多少次提交


有過Github的使用經(jīng)驗(yàn)的話使用起來就已經(jīng)是很方便的了深滚。

后記

挺久前就想搭一個(gè)自己的GitLab奕谭,由于時(shí)間精力有限(其實(shí)就是懶),到最近想到挺想玩一下然后找的資料都亂七八糟的痴荐,所以踩了點(diǎn)坑血柳,到最后搭起來,希望本文對(duì)要搭GitLab的同學(xué)有所幫助生兆,然后需要漢化的話找相對(duì)應(yīng)版本的漢化包進(jìn)行覆蓋难捌,查看GitLab版本命令:

 cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

另外被qiang住的同學(xué)可使用清華大學(xué)的開源軟件鏡像 :https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce

源地址:http://www.realyoung.cc/realyoung/50.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子根吁,更是在濱河造成了極大的恐慌员淫,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,311評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件击敌,死亡現(xiàn)場(chǎng)離奇詭異介返,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)愚争,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,339評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門映皆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人轰枝,你說我怎么就攤上這事捅彻。” “怎么了鞍陨?”我有些...
    開封第一講書人閱讀 152,671評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵步淹,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我诚撵,道長(zhǎng)缭裆,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,252評(píng)論 1 279
  • 正文 為了忘掉前任寿烟,我火速辦了婚禮澈驼,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘筛武。我一直安慰自己缝其,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,253評(píng)論 5 371
  • 文/花漫 我一把揭開白布徘六。 她就那樣靜靜地躺著内边,像睡著了一般。 火紅的嫁衣襯著肌膚如雪待锈。 梳的紋絲不亂的頭發(fā)上漠其,一...
    開封第一講書人閱讀 49,031評(píng)論 1 285
  • 那天,我揣著相機(jī)與錄音竿音,去河邊找鬼和屎。 笑死,一個(gè)胖子當(dāng)著我的面吹牛春瞬,可吹牛的內(nèi)容都是我干的柴信。 我是一名探鬼主播,決...
    沈念sama閱讀 38,340評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼快鱼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起抹竹,我...
    開封第一講書人閱讀 36,973評(píng)論 0 259
  • 序言:老撾萬榮一對(duì)情侶失蹤线罕,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后窃判,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體钞楼,經(jīng)...
    沈念sama閱讀 43,466評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,937評(píng)論 2 323
  • 正文 我和宋清朗相戀三年袄琳,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了询件。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,039評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡唆樊,死狀恐怖宛琅,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情逗旁,我是刑警寧澤嘿辟,帶...
    沈念sama閱讀 33,701評(píng)論 4 323
  • 正文 年R本政府宣布,位于F島的核電站片效,受9級(jí)特大地震影響红伦,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜淀衣,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,254評(píng)論 3 307
  • 文/蒙蒙 一昙读、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧膨桥,春花似錦蛮浑、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,259評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至介牙,卻和暖如春壮虫,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背环础。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評(píng)論 1 262
  • 我被黑心中介騙來泰國(guó)打工囚似, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人线得。 一個(gè)月前我還...
    沈念sama閱讀 45,497評(píng)論 2 354
  • 正文 我出身青樓饶唤,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親贯钩。 傳聞我的和親對(duì)象是個(gè)殘疾皇子募狂,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,786評(píng)論 2 345