溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

centos 7部署并漢化Gitlab及基礎(chǔ)操作

發(fā)布時間:2020-10-06 19:43:27 來源:網(wǎng)絡(luò) 閱讀:675 作者:筱振 欄目:系統(tǒng)運維

Gitlab 是一個利用 Ruby on Rails 開發(fā)的開源應(yīng)用程序,實現(xiàn)一個Git 項目倉庫,可通過Web 界面進行訪問公開的或者私人的項目 Gitlab 擁有與 Github 類似的功能,能夠瀏覽源代碼,管理缺陷和注釋??梢怨芾韴F隊對倉庫的訪問,他非常易于瀏覽提交過的版本并提供一個文件歷史庫。他還提供一個代碼片段收集功能可以輕松實現(xiàn)代碼復(fù)用,便于日后有需要的時候進行查找。

關(guān)于gitlab的詳細信息建議參考gitlab官網(wǎng)進行詳細的了解!

博文大綱:
一、準備環(huán)境
二、安裝Gitlab
三、漢化Gitlab
四、gitlab基本操作
五、遠端庫的基本操作
六、重置gitlab管理員密碼

一、準備環(huán)境

操作系統(tǒng) 內(nèi)存 CPU
centos 7 4G以上 雙核

二、安裝Gitlab

1)安裝Gitlab所需依賴
[root@gitlab ~]# yum -y install  epel-release curl openssh-server openssh-clients postfix cronie policycoreutils-python
2)獲取Gitlab的RPM軟件包

方法一:通過清華大學(xué)的開源鏡像站獲取軟件包(推薦)

[root@gitlab ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm

方法二:通過Gitlab官網(wǎng)來獲取軟件包(網(wǎng)絡(luò)穩(wěn)定時使用)

[root@gitlab ~]# wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm/download.rpm
3)安裝Gitlab
[root@gitlab ~]# rpm -ivh gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm 
#安裝時間較長,耐心等待,安裝過程中會出現(xiàn)gitlab的logo
4) 修改gitlab的url并執(zhí)行reconfigure
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb         #修改gitlab的配置文件
………………………………                 #省略部分內(nèi)容
external_url 'http://192.168.1.8'                       #將此處改為本機的IP地址,便于訪問
[root@gitlab ~]# gitlab-ctl reconfigure        #重新配置gitlab,就算不修改配置文件,也需要在安裝后重新配置gitlab
5)web頁面訪問測試

如圖:
centos 7部署并漢化Gitlab及基礎(chǔ)操作
可以訪問到表示沒有問題,但是都是英文界面,對于英文不好的我表示很是頭疼,還好可以通過一些方法使其漢化,方法如下!

三、漢化Gitlab

1)獲取gitlab漢化補丁包(如果不需要漢化,則跳過此步驟即可)
[root@gitlab ~]# head -1 /opt/gitlab/version-manifest.txt           #查看gitlab的版本
gitlab-ce 12.3.5
[root@gitlab ~]# git clone https://gitlab.com/xhang/gitlab.git -b v12.3.5-zh
#獲取漢化補丁包(注意需與gitlab的版本保持一致)
[root@gitlab ~]# cd gitlab/               #進入剛才clone下來的gitlab目錄
[root@gitlab gitlab]# git diff v12.3.5 v12.3.5-zh > /root/v12.3.5-zh.diff
#用diff將英文原版與中文版的對比生成.diff文件
2)將中文補丁導(dǎo)入gitlab
[root@gitlab gitlab]# gitlab-ctl stop              #停止gitlab
[root@gitlab gitlab]# yum -y install patch
[root@gitlab gitlab]# patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 <  ../v12.3.5-zh.diff
 #將剛才的diff文件做為補丁導(dǎo)入到gitlab中
#該命令執(zhí)行過程中,一路回車跳過即可
[root@gitlab gitlab]# gitlab-ctl start                 #啟動gitlab
[root@gitlab gitlab]# gitlab-ctl reconfigure      #重新配置gitlab
3)web頁面再次訪問

如圖:
centos 7部署并漢化Gitlab及基礎(chǔ)操作
centos 7部署并漢化Gitlab及基礎(chǔ)操作
centos 7部署并漢化Gitlab及基礎(chǔ)操作

四、gitlab基本操作

1)配置SSH方式免密登錄
[root@gitlab ~]# ssh-keygen -t rsa -C "1454295320@qq.com"
#生成秘鑰對,一路回車即可,“-C”后是自己的郵箱
[root@gitlab ~]# cat ~/.ssh/id_rsa.pub         #查看生成的公鑰并復(fù)制 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvNm+nXc59ugb0SGr9iMHDSFjvmdSJk0ORuX3hbjt822Y2ofXysUrIuBSQ1Jn0Rss/LPU54K32i4bIDsa/jD9gIpN/GqU+YP1MQ9bEw3YVUONAs+nYeWJWahQ1rMTeM0HC9aKvNTrNsOqrXIboJymBrs6Odt+1NnZsYHMwA/KlpYCFsi0HQgBzsLbrD5v++cIDTvM/V4rMq6fqFsfWoYYMHWc8JeNMl/aWJV1RhJpt7wm17FEv3XiH+wyoef5ZYI60IkH5qMJkjWhKcRXCWG5SH3nphUb1fmktB4DH92TW/EGw///VQEnE7tkpNjyJpOTXDuHnEk2tw43cctDN2sJH 1454295320@qq.com

回到web頁面,操作如下:
centos 7部署并漢化Gitlab及基礎(chǔ)操作
centos 7部署并漢化Gitlab及基礎(chǔ)操作
centos 7部署并漢化Gitlab及基礎(chǔ)操作

2)創(chuàng)建一個基本庫

如圖:
centos 7部署并漢化Gitlab及基礎(chǔ)操作
centos 7部署并漢化Gitlab及基礎(chǔ)操作
centos 7部署并漢化Gitlab及基礎(chǔ)操作
回到服務(wù)器上輸入測試的命令,如下:

[root@gitlab ~]# git config --global user.name "Administrator"
[root@gitlab ~]# git config --global user.email "admin@example.com"
[root@gitlab ~]# git clone git@192.168.1.8:root/test01.git         
#克隆到本地,根據(jù)提示輸入“yes”即可!
[root@gitlab ~]# cd test01/
[root@gitlab test01]# touch README.md
[root@gitlab test01]# git add README.md
[root@gitlab test01]# git commit -m "add README"
[root@gitlab test01]# git push -u origin master

刷新web頁面即可,如圖:
centos 7部署并漢化Gitlab及基礎(chǔ)操作

五、遠端庫的基本操作

當(dāng)你從遠端倉庫克隆時,實際上git自動把本地的master分支和遠端的master分支對應(yīng)起來了,并且遠程倉庫的默認名稱是origin。

1)查看關(guān)聯(lián)的遠程庫的信息
[root@gitlab test01]# git remote        #簡潔信息
origin
[root@gitlab test01]# git remote -v         #詳細信息
origin  git@192.168.1.8:root/test01.git (fetch)
origin  git@192.168.1.8:root/test01.git (push)
2)推送分支到遠程倉庫
[root@gitlab test01]# git checkout -b dev             #創(chuàng)建并切換到dev分支
[root@gitlab test01]# git push origin dev              #將本地的分支推送到遠程倉庫

刷新頁面之后,如圖:
centos 7部署并漢化Gitlab及基礎(chǔ)操作

3)解決多人協(xié)作產(chǎn)生的問題

當(dāng)我們整個小組對同一個分支進行開發(fā)時,如果在你提交之前,你的同事已經(jīng)修改了分支的內(nèi)容并推送到遠端倉庫,而碰巧你也對同樣的文件做了修改,并試圖推送,那么會推送失敗,因為你的同事的最新提交的數(shù)據(jù)和你試圖提交的數(shù)據(jù)有沖突(你本地的內(nèi)容比遠端倉庫的舊了),解決的辦法會在提示你推送失敗的返回信息中給出,這里我們模擬一下這一過程。

#進入另一個目錄,克隆遠端倉庫,模擬多人操作
[root@gitlab test01]# cd /tmp           
[root@gitlab tmp]# git clone git@192.168.1.8:root/test01.git
[root@gitlab tmp]# cd test01/
[root@gitlab test01]# git checkout -b etc            #重新創(chuàng)建一個分支并切換
[root@gitlab test01]# echo -e "touch /tmp/test01" > tmp.txt
[root@gitlab test01]# git add tmp.txt
[root@gitlab test01]# git commit -m "commmit from /tmp"
[root@gitlab test01]# git push origin etc                #將新修改的內(nèi)容推送到遠端

回到web界面進行刷新,即可看到新提交的分支:
centos 7部署并漢化Gitlab及基礎(chǔ)操作
centos 7部署并漢化Gitlab及基礎(chǔ)操作

#上述操作是在/tmp目錄下執(zhí)行的,接下來的操作在/root目錄下執(zhí)行:
[root@gitlab test01]# cd /root/test01/
[root@gitlab test01]# git checkout -b etc
[root@gitlab test01]# echo "touch /root/test01.txt" > root.txt
[root@gitlab test01]# git add root.txt
[root@gitlab test01]# git commit -m "commit from /root"
[root@gitlab test01]# git push origin  etc            
#再次推送,將會出現(xiàn)以下錯誤
To git@192.168.1.8:root/test01.git
 ! [rejected]        etc -> etc (fetch first)
error: 無法推送一些引用到 'git@192.168.1.8:root/test01.git'
提示:更新被拒絕,因為遠程版本庫包含您本地尚不存在的提交。這通常是因為另外
提示:一個版本庫已推送了相同的引用。再次推送前,您可能需要先合并遠程變更
提示:(如 'git pull')。
提示:詳見 'git push --help' 中的 'Note about fast-forwards' 小節(jié)。
[root@gitlab test01]# git pull origin etc              #將遠端的etc分支pull到本地
[root@gitlab test01]# ls               #可以看出在/tmp目錄下提交的文件就存在了
README.md  root.txt  tmp.txt
[root@gitlab test01]# git push origin etc                  #然后再次將本地的dev分支推送到gitlab,即可成功

再次刷新web頁面,etc分支下就會有了我們在/tmp目錄和/root目錄下提交的所有內(nèi)容,如圖:
centos 7部署并漢化Gitlab及基礎(chǔ)操作

4)合并遠程分支
[root@gitlab test01]# git checkout master           #切換至master分支
[root@gitlab test01]# git merge etc                    #合并etc分支
[root@gitlab test01]# ls                   #查看合并后的分支下內(nèi)容
README.md  root.txt  tmp.txt
[root@gitlab test01]# git add .
[root@gitlab test01]# git commit -m "提交"
[root@gitlab test01]# git push origin master             #推送到遠端版本庫

再次刷新web頁面,如圖:
centos 7部署并漢化Gitlab及基礎(chǔ)操作

5)刪除遠程的分支
[root@gitlab test01]# git branch -d etc                 #刪除本地的dev分支
[root@gitlab test01]# git branch -r -d origin/etc     #刪除指定的遠程分支
[root@gitlab test01]# git push origin :etc               #將刪除的分支提交到遠程版本庫中
[root@gitlab test01]# git branch -d dev
[root@gitlab test01]# git branch -r -d origin/dev
[root@gitlab test01]# git push origin :dev                      #同上

再次刷新web頁面,如下:
centos 7部署并漢化Gitlab及基礎(chǔ)操作

六、重置gitlab管理員密碼

[root@gitlab ~]# gitlab-rails console production             #必須是root用戶登錄服務(wù)器執(zhí)行該命令
irb(main):001:0> user = User.where(id: 1).first             #id為1的是超級管理員
irb(main):002:0> user.password = 'yourpassword'       #密碼必須至少8個字符
irb(main):003:0> user.save!                  #保存用戶修改信息,如沒有問題返回true
irb(main):004:0> exit                             #退出

至此,再次登錄,就需要使用新密碼yourpassword進行登錄了。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI