前言
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)境配置
- 系統(tǒng):Red-Hat系列CentOS 7.x-x86_64(筆者采用的是CentOS7.2)
- CPU:建議雙核以上
- 內(nèi)存:2GB(官方建議4GB以上,請(qǐng)看下圖官方給出的建議)
安裝
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)
此時(shí)此刻萝快,GitLab 終于裝上了! 然后按照提示 修改 /etc/gitlab/gitlab.rb 把 external_url 中的地址修改一下
完成之后執(zhí)行
gitlab-ctl reconfigure
繼續(xù)靜靜地等待配置和啟動(dòng)服務(wù)完成….
終于等到完成了插佛,立馬在瀏覽器中輸入地址杠巡,結(jié)果..
甚至出現(xiàn)無法連接服務(wù)器,這并不是我想要的結(jié)果雇寇! 于是我立馬看了下gitlab的狀態(tài)
gitlab-ctl status
發(fā)現(xiàn)并沒有什么問題啊氢拥,一切正常,這時(shí)候心中千萬只草泥馬在奔馳最后實(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