源碼安裝 GitLab 步驟繁瑣:需要安裝依賴包塔淤,Mysql阱飘,Redis斥杜,Postfix虱颗,Ruby,Nginx……安裝完畢還得一個(gè)個(gè)手動(dòng)配置這些軟件蔗喂。源碼安裝容易出錯(cuò)忘渔,不順利的話,一天都搞不定缰儿。源碼最大的好處是私人定制畦粮,如果不做定制化,還是使用官方推薦的 omnibus packages 方式安裝乖阵,網(wǎng)絡(luò)好的話宣赔,一個(gè)小時(shí)內(nèi)搞定。
參照官方安裝文檔瞪浸,分別在 Ubuntu 14 和 CentOS 6 兩個(gè)機(jī)器上安裝儒将,過程非常順利,沒有錯(cuò)誤对蒲。
在 Ubuntu 14 安裝
使用國(guó)內(nèi)安裝源鏡像钩蚊,加快安裝速度。修改/etc/apt/sources.list.d/gitlab-ce.list
蹈矮,添加以下行
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/debian jessie main
開始安裝:
# 安裝依賴包
sudo apt-get install curl openssh-server ca-certificates postfix
# 安裝 GitLab 社區(qū)版
apt-get install gitlab-ce
# 初始化两疚,初始化完自動(dòng)啟動(dòng) GitLab
sudo gitlab-ctl reconfigure
在 CentOS 6 安裝
使用國(guó)內(nèi)鏡像安裝,新建 /etc/yum.repos.d/gitlab-ce.repo含滴,添加以下內(nèi)容
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
安裝步驟:
# 安裝依賴包
sudo yum install curl openssh-server openssh-clients postfix cronie
# 啟動(dòng) postfix 郵件服務(wù)
sudo service postfix start
# 檢查 postfix
sudo chkconfig postfix on
# 安裝 GitLab 社區(qū)版
sudo yum install gitlab-ce
# 初始化 GitLab
sudo gitlab-ctl reconfigure
修改 host
添加訪問的 host,修改/etc/gitlab/gitlab.rb
的external_url
external_url 'http://git.home.com'
vi /etc/hosts
丐巫,添加 host 映射
127.0.0.1 git.home.com
每次修改/etc/gitlab/gitlab.rb
谈况,都要運(yùn)行以下命令,讓配置生效
sudo gitlab-ctl reconfigure
配置本機(jī)的 host递胧,如:192.168.113.59 git.home.com
碑韵。最后,在瀏覽器打開網(wǎng)址http://git.home.com
缎脾,登陸祝闻。默認(rèn)管理員:
用戶名: root
密碼: 5iveL!fe
安裝中文語言包(漢化)
以下漢化步驟參考此篇文章,首先確認(rèn)當(dāng)前安裝版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
當(dāng)前安裝版本是8.5.7
遗菠,因此中文補(bǔ)丁需要打8.5版本
联喘。
克隆 GitLab 源碼倉(cāng)庫:
# 克隆 GitLab.com 倉(cāng)庫
git clone https://gitlab.com/larryli/gitlab.git
#或 Gitcafe.com 鏡像辙纬,速度更快
git clone https://gitcafe.com/larryli/gitlab.git
運(yùn)行漢化補(bǔ)痘碓狻:
# 8.5 版本的漢化補(bǔ)丁(8-5-stable是英文穩(wěn)定版贺拣,8-5-zh是中文版蓖谢,兩個(gè) diff 結(jié)果便是漢化補(bǔ)段嬖獭)
sudo git diff origin/8-5-stable..8-5-zh > /tmp/8.5.diff
# 停止 gitlab
sudo gitlab-ctl stop
# 應(yīng)用漢化補(bǔ)丁
cd /opt/gitlab/embedded/service/gitlab-rails
git apply /tmp/8.5.diff
# 啟動(dòng)gitlab
sudo gitlab-ctl start
至此,漢化完畢闪幽。打開地址http://git.home.com
啥辨,便會(huì)看到中文版的GitLab
。如下
安裝完成盯腌。
備份
如果是生產(chǎn)環(huán)境溉知,備份是必須的。需要備份的文件:配置文件和數(shù)據(jù)文件腊嗡。
備份配置文件
配置文件含密碼等敏感信息着倾,不要和數(shù)據(jù)備份文件放在一起。
sh -c 'umask 0077; tar -cf $(date "+etc-gitlab-%s.tar") -C /etc/gitlab'
備份數(shù)據(jù)文件
默認(rèn)數(shù)據(jù)備份目錄是/var/opt/gitlab/backups
燕少,手動(dòng)創(chuàng)建備份文件:
# Omnibus 方式安裝使用以下命令備份
sudo gitlab-rake gitlab:backup:create
日常備份卡者,添加 crontab,運(yùn)行crontab -e
# 每天2點(diǎn)執(zhí)行備份
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
如要修改備份周期和目錄客们,在/etc/gitlab/gitlab.rb
中修改以下兩個(gè)選項(xiàng)
# 設(shè)置備份周期為7天 - 604800秒
gitlab_rails['backup_keep_time'] = 604800
# 備份目錄
gitlab_rails['backup_path'] = '/mnt/backups'
恢復(fù)
恢復(fù)之前崇决,確保備份文件所安裝 GitLab 和當(dāng)前要恢復(fù)的 GitLab 版本一致。首先底挫,恢復(fù)配置文件:
sudo mv /etc/gitlab /etc/gitlab.$(date +%s)
# 將下面配置備份文件的時(shí)間戳改為你所備份的文件的時(shí)間戳
sudo tar -xf etc-gitlab-1399948539.tar -C /
恢復(fù)數(shù)據(jù)文件
# 將數(shù)據(jù)備份文件拷貝至備份目錄
sudo cp 1393513186_gitlab_backup.tar /var/opt/gitlab/backups/
# 停止連接數(shù)據(jù)庫的進(jìn)程
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
# 恢復(fù)1393513186這個(gè)備份文件恒傻,將覆蓋GitLab數(shù)據(jù)庫!
sudo gitlab-rake gitlab:backup:restore BACKUP=1393513186
# 啟動(dòng) GitLab
sudo gitlab-ctl start
# 檢查 GitLab
sudo gitlab-rake gitlab:check SANITIZE=true
持續(xù)集成(GitLab-CI)
GitLab 從 8.0 之后就集成了GitLab-CI建邓,所以不需要再另外安裝 CI唱凯。但需要安裝Runner
1.添加 Runner 安裝源
# For Debian/Ubuntu
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash
# For CentOS
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash
安裝gitlab-ci-multi-runner
# For Debian/Ubuntu
apt-get install gitlab-ci-multi-runner
# For CentOS
yum install gitlab-ci-multi-runner
2.注冊(cè) Runner。獲取Token:以管理員身份登錄GitLab忌栅,進(jìn)入管理區(qū)域锄贼,點(diǎn)擊側(cè)邊欄的Runner,如下圖注簿,“注冊(cè)授權(quán)碼”后的字符串便是Token契吉。
sudo gitlab-ci-multi-runner register
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci):
http://git.home.com/ci
Please enter the gitlab-ci token for this runner:
xxxx # 輸入Token
Please enter the gitlab-ci description for this runner:
[xxy-web-test-02]: test-runner # 輸入runner的名稱
Please enter the gitlab-ci tags for this runner (comma separated):
test,php # 輸入runner的標(biāo)簽,以區(qū)分不同的runner诡渴,標(biāo)簽間逗號(hào)分隔
Registering runner... succeeded runner=YDPz2or3
Please enter the executor: ssh, shell, parallels, docker, docker-ssh, virtualbox:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
注冊(cè)完成便可在上圖中查看你所注冊(cè)的Runner捐晶。至此,所有安裝完畢妄辩,Runner的構(gòu)建惑灵,后續(xù)補(bǔ)充。