搭建屬于自己的GitLab
一:硬件需求
存儲(chǔ)
存儲(chǔ)空間的大小主要取決于你將存儲(chǔ)的Git倉(cāng)庫(kù)的大小费就。但根據(jù) rule of thumb(經(jīng)驗(yàn)法則) 你應(yīng)該考慮多留一些空間用來(lái)存儲(chǔ)Git倉(cāng)庫(kù)的備份瘾敢。
如果你想使用彈性的存儲(chǔ)空間,你可以考慮在分配分區(qū)的時(shí)候使用LVM架構(gòu),這樣可以在后期需要的清空下添加硬盤(pán)在增加存儲(chǔ)空間吼畏。
除此之外你還可以掛在一個(gè)支持NFS的分卷妖啥,比如NAS、 SAN芝硬、AWS、EBS轧房。
如果你的服務(wù)器有足夠大的內(nèi)存和CPU處理性能拌阴,GitLab的響應(yīng)速度主要受限于硬盤(pán)的尋道時(shí)間。 使用更快的硬盤(pán)(7200轉(zhuǎn))或者SSD硬盤(pán)會(huì)很大程度的提升GitLab的響應(yīng)速度奶镶。
CPU
- 1 核心CPU最多支持100個(gè)用戶迟赃,所有的workers和后臺(tái)任務(wù)都在同一個(gè)核心工作這將導(dǎo)致GitLab服務(wù)響應(yīng)會(huì)有點(diǎn)緩慢。
- 2核心 支持500用戶厂镇,這也是官方推薦的最低標(biāo)準(zhǔn)纤壁。
- 4 核心支持2,000用戶。
- 8 核心支持5,000用戶捺信。
- 16 核心支持10,000用戶酌媒。
- 32 核心支持20,000用戶。
- 64 核心支持40,000用戶。
- 如果想支持更多用戶秒咨,可以使用 集群式架構(gòu)
Memory
安裝使用GitLab需要至少4GB可用內(nèi)存(RAM + Swap)! 由于操作系統(tǒng)和其他正在運(yùn)行的應(yīng)用也會(huì)使用內(nèi)存, 所以安裝GitLab前一定要注意當(dāng)前服務(wù)器至少有4GB的可用內(nèi)存. 少于4GB內(nèi)存會(huì)導(dǎo)致在reconfigure的時(shí)候出現(xiàn)各種詭異的問(wèn)題, 而且在使用過(guò)程中也經(jīng)常會(huì)出現(xiàn)500錯(cuò)誤.
- 1GB 物理內(nèi)存 + 3GB 交換分區(qū) 是最低的要求喇辽,但我們 強(qiáng)烈反對(duì) 使用這樣的配置。 查看下面unicorn worker章節(jié)獲取更多建議雨席。
- 2GB 物理內(nèi)存 + 2GB 交換分區(qū) 支持100用戶菩咨,但服務(wù)響應(yīng)會(huì)很慢。
- 4GB 物理內(nèi)存 支持100用戶陡厘,也是 官方推薦 的配置抽米。
- 8GB 物理內(nèi)存 支持 1,000 用戶。
- 16GB 物理內(nèi)存 支持 2,000 用戶糙置。
- 32GB 物理內(nèi)存 支持 4,000 用戶缨硝。
- 64GB 物理內(nèi)存 支持 8,000 用戶。
- 128GB 物理內(nèi)存 支持 16,000 用戶罢低。
- 256GB 物理內(nèi)存 支持 32,000 用戶查辩。
- 如果想支持更多用戶,可以使用 集群式架構(gòu)
官網(wǎng) https://about.gitlab.com/downloads/
二:"git" 家族的成員
首先解決一個(gè)容易混淆的問(wèn)題网持,我也經(jīng)常搞混:
| git | 是一種版本控制系統(tǒng)宜岛,是一個(gè)命令,是一種工具 |
| gitlib | 是用于實(shí)現(xiàn)git功能的開(kāi)發(fā)庫(kù) |
| github | 是一個(gè)基于git實(shí)現(xiàn)的在線代碼托管倉(cāng)庫(kù)功舀,包含一個(gè)網(wǎng)站界面萍倡,向互聯(lián)網(wǎng)開(kāi)放 |
| gitlab | 是一個(gè)基于git實(shí)現(xiàn)的在線代碼倉(cāng)庫(kù)托管軟件,你可以用gitlab自己搭建一個(gè)類似于github一樣的系統(tǒng)辟汰,一般用于在企業(yè)列敲、學(xué)校等內(nèi)部網(wǎng)絡(luò)搭建git私服 |
三:官方推薦安裝
1、安裝依賴包
yum 方式:
如想使用Postfix來(lái)發(fā)送郵件,在安裝期間請(qǐng)選擇’Internet Site’. 您也可以用sendmai或者 配置SMTP服務(wù) 并 使用SMTP發(fā)送郵件.在 Centos 6 系統(tǒng)上, 下面的命令將在系統(tǒng)防火墻里面開(kāi)放HTTP和SSH端口.
yum install curl policycoreutils openssh-server openssh-clients
確保sshd啟動(dòng)(正常情況下, sshd是啟動(dòng)的)
systemctl enable sshd && systemctl start sshd
yum install postfix
systemctl enable postfix && systemctl start postfix
永久設(shè)置http服務(wù)開(kāi)放
firewall-cmd --permanent --add-service=http
也可關(guān)閉防火墻
停止firewall
systemctl stop firewalld.service
禁止firewall開(kāi)機(jī)啟動(dòng)
systemctl disable firewalld.service
更新防火墻規(guī)則
systemctl reload firewalld
查看防火墻狀態(tài)
firewall-cmd --state
apt方式:
sudo apt-get install curl openssh-server ca-certificates postfix
2帖汞、安裝 gitlab-ce 社區(qū)版 (ee是企業(yè)版戴而,收費(fèi))
yum方式:
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh |sudo bash
yum install gitlab-ce
apt 方式:
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce
下面是yum方式
[root@aliyun ~]# yum install gitlab-ce -y
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解決依賴關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 gitlab-ce.x86_64.0.10.3.3-ce.0.el7 將被 安裝
--> 解決依賴關(guān)系完成
依賴關(guān)系解決
==================================================================================================================================================================================
Package 架構(gòu) 版本 源 大小
==================================================================================================================================================================================
正在安裝:
gitlab-ce x86_64 10.3.3-ce.0.el7 gitlab_gitlab-ce 377 M
事務(wù)概要
==================================================================================================================================================================================
安裝 1 軟件包
總下載量:377 M
安裝大小:1.1 G
成功安裝 gitlab-ce-10.3.3-ce.0.el7.x86_64
2翩蘸、安裝 gitlab-ce 社區(qū)版(rpm包安裝方式)
wget [https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-XXX.rpm/download](https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-XXX.rpm/download)
rpm -i gitlab-ce-XXX.rpm
3所意、可更換國(guó)內(nèi)源
如果下載速度慢可更換國(guó)內(nèi)源,詳細(xì)見(jiàn): Centos7 更換國(guó)內(nèi)的yum源
4催首、配置并開(kāi)啟 gitlab
如果設(shè)備配置比較低, 會(huì)在啟動(dòng)過(guò)程中卡死, 建議最低雙核2G內(nèi)存
gitlab-ctl reconfigure //此時(shí)會(huì)輸入如下很多信息扶踊,并啟動(dòng)好多服務(wù)
5、檢查狀態(tài)
[root@db01 src]# gitlab-ctl status
run: gitaly: (pid 23978) 37s; run: log: (pid 23342) 134s
run: gitlab-monitor: (pid 23998) 37s; run: log: (pid 23576) 122s
run: gitlab-workhorse: (pid 23958) 38s; run: log: (pid 23067) 152s
run: logrotate: (pid 23245) 140s; run: log: (pid 23244) 140s
run: nginx: (pid 23156) 146s; run: log: (pid 23155) 146s
run: node-exporter: (pid 23518) 128s; run: log: (pid 23517) 128s
run: postgres-exporter: (pid 24042) 34s; run: log: (pid 23757) 104s
run: postgresql: (pid 22636) 220s; run: log: (pid 22635) 220s
run: prometheus: (pid 24021) 35s; run: log: (pid 23688) 110s
run: redis: (pid 22503) 226s; run: log: (pid 22502) 226s
run: redis-exporter: (pid 23632) 116s; run: log: (pid 23631) 116s
run: sidekiq: (pid 22998) 158s; run: log: (pid 22997) 158s
run: unicorn: (pid 22930) 164s; run: log: (pid 22929) 164s
[root@db01 src]#
6郎任、測(cè)試訪問(wèn)
首次登陸會(huì)跳出設(shè)置密碼的界面秧耗,設(shè)置完后自動(dòng)跳轉(zhuǎn)到登錄界面,默認(rèn)用戶名root舶治。
登陸進(jìn)去后分井,可以更改用戶名胶台、密碼等。
ifconfig eth0|awk -F '[ :]+' 'NR==2{print $4}'
# 獲取網(wǎng)卡地址
7杂抽、說(shuō)明
缺點(diǎn):這種方式雖然說(shuō)簡(jiǎn)單方便诈唬,但是定制型很差,默認(rèn)只能使用postgre和nginx
主配置文件:/etc/gitlab/gitlab.rb //可以自定義一些郵件服務(wù)等
日志地址:/var/log/gitlab/ // 對(duì)應(yīng)各服務(wù)
服務(wù)地址:/var/opt/gitlab/ // 對(duì)應(yīng)各服務(wù)的主目錄
倉(cāng)庫(kù)地址:/var/opt/gitlab/git-data //記錄項(xiàng)目倉(cāng)庫(kù)等提交信息
重置配置:gitlab-ctl reconfigure //不要亂用缩麸,會(huì)重置為最原始的配置的
重啟服務(wù):gitlab-ctl stop/start/restart //啟動(dòng)命令
默認(rèn)安裝:postgres铸磅、nginx、redis杭朱、unicorn ......
四:安裝漢化包
4.1 準(zhǔn)備環(huán)境
[root@db01 ~]# cd /data/src/
[root@db01 src]# git clone https://gitlab.com/xhang/gitlab.git
-bash: git: command not found
[root@db01 src]# yum -y install git
[root@db01 src]# git clone https://gitlab.com/xhang/gitlab.git
4.2 停止gitlab
[root@db01 ~]# gitlab-ctl stop
4.3 漢化操作
# 查看改漢化補(bǔ)丁版本
[root@db01 src]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 10.8.4
也可以
[root@db01 src]# cat gitlab/VERSION
10.8.4
4.4 獲取gitlab漢化包
[root@db01 src]# cd gitlab/
[root@db01 gitlab]# git diff v10.8.4 v10.8.4-zh > /tmp/10.8.4.diff
[root@db01 gitlab]#
4.5 更新補(bǔ)丁到gitlab中
[root@db01 gitlab]# yum -y install patch
[root@db01 gitlab]# cd /tmp/
[root@db01 tmp]# patch -d/opt/gitlab/embedded/service/gitlab-rails -p1 < 10.8.4.diff
注意:可能會(huì)出來(lái)該情況 一路回車跳過(guò)即可阅仔!
4.6 重新配置gitlab
[root@db01 tmp]# gitlab-ctl reconfigure
[root@db01 tmp]# gitlab-ctl start
五、gitlal管理設(shè)置
5.1 設(shè)置管理密碼
5.2 創(chuàng)建gitlab群組
5.3 給群組創(chuàng)建項(xiàng)目
創(chuàng)建完成之后它提示我們可以創(chuàng)建一個(gè)key對(duì)它進(jìn)行管理
我們點(diǎn)擊上面的README然后我們隨便在里面寫(xiě)點(diǎn)東西
5.4 添加密鑰
[root@db01 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
f7:66:6d:4c:74:38:70:8b:47:df:78:5c:4c:bd:2a:ed root@db01
The key's randomart image is:
+--[ RSA 2048]----+
| . oo+|
| = *=|
| . B B|
| o = |
| S . . o |
| . o * |
| * + |
| o E |
| |
+-----------------+
[root@db01 ~]#
查看公共密鑰
[root@db01 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqgVmWXspLgcvmhKfXk83Hj14n5EXE1GHzIc7FD747jH2wTGgRUCcaHIJ4QAwmAqta312SM2vlZQiuNaaZYDa01QBlnpZbimxcQolbvcFISH3HB/O5iPX/Hri4nEKnfSL72N9QTQMDTVJhCDuv6rP1ptusuNGliXyQRvaypWqUlfBkFIUc3gB8fhhXLrxNxeYdmLfCB7ZqyJSpELTxunDtUo68taA3bJADVYbhRzY+85YT1BW3ggtVlzyYBqsWboO+QNGGNUmJ/tvVh9tFez5zgqJSMlTqGLbfrv+rCKIDZVpGotooxMzMDsDZnW26NcfRJeDV6E7C4hOODg6l3XQ4Q== root@db01
[root@db01 ~]#
5.5 添加免密驗(yàn)證
5.6 拉取代碼
5.6.1 創(chuàng)建代碼目錄
[root@db01 ~]# mkdir /data/code -p
[root@db01 ~]# cd /data/code/
[root@db01 code]#
5.6.2 git拉取代碼
沒(méi)有安裝git直接yum
yum -y install git
[root@db01 code]# git clone git@gitlab.example.com:web/web-demo.git
Initialized empty Git repository in /data/code/web-demo/.git/
The authenticity of host 'gitlab.example.com (2x7.xxx.3x.xxx)' can't be established.
RSA key fingerprint is 58:61:9a:f3:c9:b0:cf:xx:16:7e:d3:8c:xx:d9:aa:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.example.com,2x7.xxx.xx.xxx' (RSA) to the list of known hosts.
warning: You appear to have cloned an empty repository.
[root@db01 code]# ll
total 4
drwxr-xr-x. 3 root root 4096 May 15 13:21 web-demo
[root@db01 code]#
5.6.3 先hosts修改制定一下域名弧械,后續(xù)修改成地址
[root@db01 code]# tail -1 /etc/hosts
2xx.xxx.xx.xxx gitlab.example.com
[root@db01 code]# ping gitlab.example.com
PING gitlab.example.com (xx.xxx.xx.xxx) 56(84) bytes of data.
64 bytes from gitlab.example.com (2xx.xxx.xx.xxx): icmp_seq=1 ttl=64 time=0.012 ms
5.7 提交代碼
5.7.1 新建文件
[root@db01 code]# cat web-demo/index.html
hello word
創(chuàng)建第一個(gè)index.html文件
由于測(cè)試提交代碼
[root@db01 code]#git add .
[root@db01 code]#git commit -m 'add index.html'
5.7.2 添加別名
[root@db01 web-demo]# git remote add origin git@gitlab.example.com:web/web-demo.git
fatal: remote origin already exists.
[root@db01 web-demo]# git pull origin master
fatal: Couldn't find remote ref master
fatal: The remote end hung up unexpectedly
[root@db01 web-demo]# git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitlab.example.com:web/web-demo.git
* [new branch] master -> master
[root@db01 web-demo]#
5.8 修改gitlab主機(jī)名
#改成相應(yīng)的IP地址或者域名即可
[root@db01 web-demo]#vim /etc/gitlab/gitlab.rb
[root@db01 web-demo]#gitlab-ctl reconfigure
#提示:修改完需要從新配置才會(huì)生效
參考文獻(xiàn):
https://about.gitlab.com/installation/#centos-7
http://blog.51cto.com/bigboss/2129284