一靶剑、Gitlab 安裝
1. 環(huán)境準(zhǔn)備
本教程主要以 CentOS 7為主,其他系統(tǒng)請(qǐng)查看官方文檔對(duì)比贴膘。
1. 安裝和打開(kāi) 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 國(guó)外鏡像速度一向感人略号,而且是不是的還抽風(fēng)刑峡,所以在國(guó)內(nèi)搭建 Gitlab 使用的時(shí)候,還是切換成墻內(nèi)鏡像比較放心玄柠。目前官方支持的國(guó)內(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)聽(tīng)端口皇帮,增加 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)行起來(lái)之后,最終的事情就是定期的備份逞频,遇到問(wè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
來(lái)創(chuàng)建計(jì)劃任務(wù)堡掏,執(zhí)行命令:sudo crontab -e -u root
应结,為 root 用戶(hù),創(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
為了防止有問(wèn)題,還是需要執(zhí)行重新配置扮休,用來(lái)重新配置和啟動(dòng):
gitlab-ctl reconfigure
5. 遷移迎卤,及版本不一致問(wèn)題
Gitlab 遷移
Gitlab 的遷移非常簡(jiǎn)單,只需要在目標(biāo)服務(wù)器上安裝好之后玷坠,把 Gitlab 的備份文件放到備份目錄中蜗搔,然后執(zhí)行上一步的恢復(fù)備份命令即可。
Gitlab 遷移版本不一致問(wèn)題
但是Gitlab 有個(gè)不爽的地方就是八堡,不同版本號(hào)的備份文件不能相互使用樟凄。有時(shí)候備份文件是舊版本,安裝的時(shí)候自動(dòng)安裝了最新版本兄渺,這時(shí)候備份文件就沒(méi)辦法使用了缝龄,怎么辦呢?
- 先卸載掉已經(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ù)備份的目錄即可炼绘。