一催束、Gitlab 安裝
1. 環(huán)境準(zhǔn)備
本教程主要以 CentOS 7為主,其他系統(tǒng)請(qǐng)查看官方文檔對(duì)比。
1. 安裝和打開 http 和 ssh 的權(quán)限
sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
2. 安裝郵件服務(wù) postfix
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
使用其他郵件服務(wù)葱峡,可以根據(jù)官方文檔自行修改:
https://docs.gitlab.com/omnibus/settings/smtp.html
2. 鏡像切換
Gitlab 國外鏡像速度一向感人,而且是不是的還抽風(fēng)叉抡,所以在國內(nèi)搭建 Gitlab 使用的時(shí)候椰于,還是切換成墻內(nèi)鏡像比較放心淘菩。目前官方支持的國內(nèi)鏡像是清華大學(xué)的鏡像站,地址:https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/
1. 新建鏡像 repo
新建 /etc/yum.repos.d/gitlab-ce.repo
霜幼,內(nèi)容為:
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
2. 執(zhí)行命令下載
sudo yum makecache
sudo yum install gitlab-ce
3. 配置使用
安裝完成之后嫩码,可以在/etc/gitblab/gitlab.rb
中按照需求修改配置,
主要需要修改external_url
罪既,改成自己使用的 url 地址铸题。
執(zhí)行命令配置生效:
gitlab-ctl reconfigure
如果想使用已有的 nginx,或者相對(duì) gitlab 內(nèi)置 nginx 進(jìn)行高級(jí)配置的話琢感,可以參考官方文檔:
https://docs.gitlab.com/omnibus/settings/nginx.html
例如丢间,修改監(jiān)聽端口,增加 ssl 配置驹针,設(shè)置 header:
nginx['listen_port'] = 8081
# For GitLab
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
# proxy set header
nginx['proxy_set_headers'] = {
"X-Forwarded-Proto" => "http",
"CUSTOM_HEADER" => "VALUE"
}
需要注意的是烘挫,修改配置之后,都需要執(zhí)行gitlab-ctl reconfigure
命令柬甥,使配置生效饮六。
二、Gitlab 備份
Gitlab 成功運(yùn)行起來之后苛蒲,最終的事情就是定期的備份卤橄,遇到問題后的還原。
1. 備份配置
默認(rèn) Gitlab 的備份文件會(huì)創(chuàng)建在/var/opt/gitlab/backups
文件夾中臂外,格式為時(shí)間戳_日期_版本號(hào)_gitlab_backup.tar
窟扑,例如:1515031353_2018_01_04_10.3.2_gitlab_backup.tar
。
修改備份文件夾漏健,需要修改配置文件/etc/gitlab/gitlab.rb
中的:
gitlab_rails['backup_path'] = '/your_wish/backups'
然后gitlabctl-reconfigure
生效辜膝。
2. 手動(dòng)備份
命令:gitlab-rake gitlab:backup:create
會(huì)在命令執(zhí)行的時(shí)間點(diǎn),在你配置的文件夾或者默認(rèn)文件夾創(chuàng)建一個(gè)備份文件漾肮。
3. 自動(dòng)備份
Gitlab 支持 crontab
來創(chuàng)建計(jì)劃任務(wù),執(zhí)行命令:sudo crontab -e -u root
茎毁,為 root 用戶克懊,創(chuàng)建并編輯 crontab忱辅。
例如,每周二到周六的早晨創(chuàng)建一個(gè)自己命名規(guī)則的備份:
15 04 * * 2-6 umask 0077; tar cfz /secret/gitlab/backups/$(date "+etc-gitlab-\%s.tgz") -C / etc/gitlab
crontab 可以參考:
http://www.pantz.org/software/cron/croninfo.html
更多備份用法谭溉,可以參考:
https://docs.gitlab.com/omnibus/settings/backups.html#backups
4. 恢復(fù)備份
先停止 gitlab 相關(guān)服務(wù):
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
執(zhí)行備份恢復(fù)命令:
gitlab-rake gitlab:backup:restore BACKUP=1515031353_2018_01_04_10.3.2
為了防止有問題墙懂,還是需要執(zhí)行重新配置,用來重新配置和啟動(dòng):
gitlab-ctl reconfigure
5. 遷移扮念,及版本不一致問題
Gitlab 遷移
Gitlab 的遷移非常簡單损搬,只需要在目標(biāo)服務(wù)器上安裝好之后,把 Gitlab 的備份文件放到備份目錄中柜与,然后執(zhí)行上一步的恢復(fù)備份命令即可巧勤。
Gitlab 遷移版本不一致問題
但是Gitlab 有個(gè)不爽的地方就是,不同版本號(hào)的備份文件不能相互使用弄匕。有時(shí)候備份文件是舊版本颅悉,安裝的時(shí)候自動(dòng)安裝了最新版本,這時(shí)候備份文件就沒辦法使用了迁匠,怎么辦呢剩瓶?
- 先卸載掉已經(jīng)安裝的最新版Gitlab:
sudo yum remove gitlab-ce
- 在 Gitlab package 地址https://packages.gitlab.com/gitlab/gitlab-ce中找到對(duì)應(yīng)操作系統(tǒng)和版本的安裝包,例如 CentOS 7城丧,Gitlab 10.3.1對(duì)應(yīng)的是gitlab-ce-10.3.1-ce.0.el7.x86_64.rpm
執(zhí)行安裝命令
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce-10.3.1-ce.0.el7.x86_64
然后重復(fù)之前的安裝延曙、配置、恢復(fù)備份的目錄即可亡哄。
三枝缔、Gitlab 漢化
Gitlab中文社區(qū)版地址:https://gitlab.com/xhang/gitlab
- 克隆版本庫
cd /usr/local/src/
git clone https://gitlab.com/xhang/gitlab.git
- 獲取當(dāng)前Gitlab版本
gitlab_version=$(cat /opt/gitlab/embedded/service/gitlab-rails/VERSION)
- 比較漢化標(biāo)簽和原標(biāo)簽,導(dǎo)出patch用的diff文件
cd /usr/local/src/gitlab
git diff v${gitlab_version} v${gitlab_version}-zh > ../${gitlab_version}-zh.diff
- 先停止gitlab
gitlab-ctl stop
- 導(dǎo)入漢化補(bǔ)丁
patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < ../${gitlab_version}-zh.diff
PS:如果出現(xiàn)類似以下內(nèi)容磺平,則按住回車魂仍,一直跳過就行了
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js
|index eb0f06e..73e4833 100644
|--- a/app/assets/javascripts/awards_handler.js
|+++ b/app/assets/javascripts/awards_handler.js
--------------------------
File to patch:
- 然后啟動(dòng)gitlab
gitlab-ctl start
此時(shí)訪問http://IP就是中文頁面了(啟動(dòng)后馬上打開頁面可能會(huì)顯示502,稍等幾秒刷新就好了)