一本正經的搞事情
改變懶惰,成就心中的自己,並非難事
gitlab服務部署及使用
一、什么是gitlib
Gitlab 是一個基於Git實現的在線代碼倉庫托管軟件,你可以用Gitlab自己搭建一個類似於Github一樣的系統平台,一般搭建gitlab私服就是用在公司的內部
Gitlab 功能就是能夠對代碼的提交審核和問題跟蹤,這個對於軟件工程質量的管理是至關重要的
Gitlab分為社區版(CE) 和 企業版(EE) 我感覺大多數的公司還是會選擇社區版,反正我們公司是要用社區版的
部署Gitlab 是對服務器有配置要求的 建議是CPU兩核,內存4G以上(其實這就是廢話了,誰家公司還沒這樣配置的服務器呀,主要還是給虛擬機玩的朋友們提示一下)
二、實現的原理
其實gitlab的原理就是git的原理,GitHub不是也是基於Git的呀,所有簡單說一下Git的原理吧
上面的就是整個Git的工作流程:
其實上面的都是一些GIt的命令,先不管命令是做什么的,這里面有四個大塊的東西,他們分別是
- Remote:遠程倉庫
- Repository:本地倉庫
- index:暫存區
- workspace:工作區
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
Remote遠程倉庫:
遠程倉庫的內容可能被分布在多個地點的處於協作關系的本地倉庫修改,因此它可能與本地倉庫同步,也可能不同步,但是它的內容是最舊的<br>
Repository本地倉庫:
這里面保存了對象被提交過的各個版本,比起工作區和暫存區的內容,它更舊一些
git commit 后同步index的目錄樹到本地倉庫,方便下一步通過git push同步本地倉庫與遠程倉庫的同步<br>
index暫存區:
.git目錄下的index文件,暫存區會記錄git add 添加文件的相關信息(文件名、大小),不保存文件實體,通過
id
指向每個文件的實體,可以使用git status查看暫存區的狀態,暫存區標記了你當前工作區中那些內容是被git管理的
當你完成某個需求或者功能后需要提交代碼,那么第一步就是通過git add 先提交到暫存區,被git管理<br>
workspace工作區:
程序員進行開發改動的地方,是你當前看到的,內容也是最新的
平常我們開發就是拷貝遠程倉庫中的分支,基於該分支進行開發,在開發的過程就是在工作區的操作<br>
總結:
任何對象都是在工作區中誕生和修改的
任何修改都是從進入index區才開始被版本控制的
只有把修改的代碼提交到本地倉庫,該修改才能在倉庫中留下痕跡
與協助者分享本地的修改,可以push到遠程倉庫來共享
|
下面這張圖很明確的表現了他們的關系
三、Gitlab的服務構成
Gitlab有好多個東西一起構成的,分別是:
- Nginx:靜態Web服務器
- gitlab-shell:用於處理Git命令和修改authorized keys列表
- gitlab-workhorse:輕量級的反向代理服務器(這個是個敏捷的反向代理,它會處理一些大的HTTP請求,比如文件的上傳下載,其他的請求會反向代理給Gitlab Rails應用)
- logrotate:日志文件管理工具
- postgresql:數據庫
- redis:緩存數據庫
- sidekiq:用於在后台執行隊列的任務
- unicorn:Gitlab Rails應用是托管在這個服務器上面的
四、Gitlab的優點
- git是分布式的,svn不是
git分布式本地就可以用,可以隨便保存各種歷史痕跡,不用擔心污染服務器,連不上服務器也能提交代碼、查看log。 - GIT分支和SVN的分支不同
分支在SVN中實際上是版本庫中的一份copy,而git一個倉庫是一個快照,所以git 切換、合並分支等操作更快速。 - git有一個強大的代碼倉庫管理系統 - gitlab
可以很方便的管理權限、代碼review,創建、管理project
五、安裝配置gitlab
5.1. 安裝依賴包
1
|
[root@web1134 ~]
# yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python
|
5.2. 啟動postfix,並設置開機自啟
1
2
|
[root@web1134 ~]
# systemctl start postfix
[root@web1134 ~]
# systemctl enable postfix
|
5.3. 設置防火牆
1
2
3
4
5
6
7
8
|
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
或者
關閉防火牆
systemctl stop firewalld.service
#停止firewall
systemctl disable firewalld.service
#禁止firewall開機啟動
|
5.4. 下載安裝gitlab rpm包
清華開源鏡像站 :https://mirrors.tuna.tsinghua.edu.cn/
1
2
3
|
[root@web1134 ~]
# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.1.6-ce.0.el7.x86_64.rpm
[root@web1134 ~]
# rpm -i gitlab-ce-11.1.6-ce.0.el7.x86_64.rpm
|
5.5. 修改配置文件gitlab.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
## GitLab configuration settings
##! This file is generated during initial installation and **is not** modified
##! during upgrades.
##! Check out the latest version of this file to know about the different
##! settings that can be configured by this file, which may be found at:
##! https://gitlab.com/gitlab-org/omnibus-gitlab/raw/master/files/gitlab-config-template/gitlab.rb.template
## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
#external_url 'http://gitlab.example.com'
external_url
'http://192.168.73.134'
# 修改這個地方
|
5.6. 重新加載配置文件
1
2
|
[root@web1134 ~]
# gitlab-ctl reconfigure
[root@web1134 ~]
# gitlab-ctl restart
|
5.7. 查看gitlab版本
1
|
[root@web1134 ~]
# head -1 /opt/gitlab/version-manifest.txt
|
六、漢化配置
6.1.下載最新漢化包
1
|
[root@web1134 ~]
# git clone https://gitlab.com/xhang/gitlab.git
|
這個時間下載的挺長的
6.2. 停止服務
1
|
[root@web1134 ~]
# gitlab-ctl stop
|
6.3. 切換到gitlab漢化包所在的目錄
1
|
[root@web1134 ~]
# cd /root/gitlab
|
6.4. 比較漢化標簽和原標簽,導出 patch 用的 diff 文件到/root下
1
|
[root@web1134 gitlab]
# git diff v11.1.6 v11.1.6-zh > ../11.1.6-zh.diff
|
6.5. 將10.0.2-zh.diff作為補丁更新到gitlab中
1
2
3
4
5
6
|
[root@web1134 gitlab]
# cd ~
[root@web1134 ~]
# yum install patch -y
[root@web1134 ~]
# patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < 11.1.6-zh.diff
# 一路回車 覆蓋文件
|
6.6. 啟動gitlab並重新配置gitlab
1
2
|
[root@web1134 ~]
# gitlab-ctl start
[root@web1134 ~]
# gitlab-ctl reconfigure
|
七、設置發郵件功能
7.1. 修改配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
[root@web1134 ~]
# vim /etc/gitlab/gitlab.rb
修改下面信息
# 配置發送郵箱
gitlab_rails[
'smtp_enable'
] =
true
gitlab_rails[
'smtp_address'
] =
"smtp.163.com"
gitlab_rails[
'smtp_port'
] = 25
gitlab_rails[
'smtp_user_name'
] =
"smtp user@163.com"
gitlab_rails[
'smtp_password'
] =
"password"
gitlab_rails[
'smtp_domain'
] =
"163.com"
gitlab_rails[
'smtp_authentication'
] =
"login"
gitlab_rails[
'smtp_enable_starttls_auto'
] =
true
# 修改gitlab配置的發信人
gitlab_rails[
'gitlab_email_from'
] =
"smtp user@163.com"
user[
"git_user_email"
] =
"smtp user@163.com"
|
7.2. 重新加載配置並重啟服務
1
2
|
[root@web1134 ~]
# gitlab-ctl reconfigure
[root@web1134 ~]
# gitlab-ctl restart
|
八、測試使用
登錄地址就是服務器IP地址 http://192.168.73.134
用戶名是root
-------------------------------------------
個性簽名:在逆境中要看到生活的美,在希望中別忘記不斷奮斗
如果覺得這篇文章對你有小小的幫助的話,記得在右下角點個“推薦”哦,博主在此感謝!
萬水千山總是情,打賞一分行不行,所以如果你心情還比較高興,也是可以掃碼打賞博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!

