Linux下GitLab的快速安裝以及備份


源碼安裝 GitLab 步驟繁瑣:需要安裝依賴包,Mysql,Redis,Postfix,Ruby,Nginx……安裝完畢還得一個個手動配置這些軟件,容易出錯

一、安裝

在Ubuntu 14上

修改/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 社區版
apt-get install gitlab-ce
# 初始化,初始化完自動啟動 GitLab
sudo gitlab-ctl reconfigure

在 CentOS 6上

新建 /etc/yum.repos.d/gitlab-ce.repo,添加以下內容

[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

在 Centos7/REHL7 上

[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0 gpgcheck=0 enabled=1 gpgkey=https://packages.gitlab.com/gpg.key

安裝步驟:

# 安裝依賴包
yum install curl openssh-server openssh-clients postfix cronie
# 啟動 postfix 郵件服務
service postfix start
# 檢查 postfix
 chkconfig postfix on
# 安裝 GitLab 社區版
yum install gitlab-ce
# 初始化 GitLab
gitlab-ctl reconfigure

登錄訪問

添加訪問的 host,修改/etc/gitlab/gitlab.rbexternal_url

external_url 'http://git.test.com'

每次修改/etc/gitlab/gitlab.rb,都要運行以下命令,讓配置生效

gitlab-ctl reconfigure

在瀏覽器打開網址http://git.test.com,登陸。默認管理員:

用戶名: root
密碼: 5iveL!fe

二、安裝中文語言包(漢化)

以下漢化步驟參考此篇文章,首先確認當前安裝版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

當前安裝版本是8.5.7,因此中文補丁需要打8.5版本

克隆 GitLab 源碼倉庫:

# 克隆 GitLab.com 倉庫
git clone https://gitlab.com/larryli/gitlab.git
#或 Gitcafe.com 鏡像,速度更快
git clone https://gitcafe.com/larryli/gitlab.git
git clone https://git.coding.net/larryli/gitlab.git

運行漢化補丁:

# 8.5 版本的漢化補丁(8-5-stable是英文穩定版,8-5-zh是中文版,兩個 diff 結果便是漢化補丁)
git diff origin/8-5-stable..8-5-zh > /tmp/8.5.diff
# 停止 gitlab
gitlab-ctl stop
# 應用漢化補丁
cd /opt/gitlab/embedded/service/gitlab-rails
git apply /tmp/8.5.diff  
# 啟動gitlab
gitlab-ctl start

至此,漢化完畢

gitlab 8.8版本

git diff origin/8-8-stable origin/8-8-zh > /tmp/8.8.diff 

三、備份

配置文件含密碼等敏感信息,不要和數據備份文件放在一起

sh -c 'umask 0077; tar -cf $(date "+etc-gitlab-%s.tar") -C /etc/gitlab'

默認數據備份目錄是/var/opt/gitlab/backups,手動創建備份文件:

# Omnibus 方式安裝使用以下命令備份
gitlab-rake gitlab:backup:create

日常備份,添加 crontab,運行crontab -e

# 每天2點執行備份
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1

如要修改備份周期和目錄,在/etc/gitlab/gitlab.rb中修改以下兩個選項

# 設置備份周期為7天 - 604800秒
gitlab_rails['backup_keep_time'] = 604800
# 備份目錄
gitlab_rails['backup_path'] = '/mnt/backups'

恢復之前,確保備份文件所安裝 GitLab 和當前要恢復的 GitLab 版本一致。首先,恢復配置文件:

mv /etc/gitlab /etc/gitlab.$(date +%s)
# 將下面配置備份文件的時間戳改為你所備份的文件的時間戳
tar -xf etc-gitlab-1399948539.tar -C /

恢復數據文件

# 將數據備份文件拷貝至備份目錄
cp 1393513186_gitlab_backup.tar /var/opt/gitlab/backups/

# 停止連接數據庫的進程
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

# 恢復1393513186這個備份文件,將覆蓋GitLab數據庫!
gitlab-rake gitlab:backup:restore BACKUP=1393513186

# 啟動 GitLab
gitlab-ctl start

# 檢查 GitLab
gitlab-rake gitlab:check SANITIZE=true

四、持續集成(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.注冊 Runner

獲取Token:以管理員身份登錄GitLab,進入管理區域,點擊側邊欄的Runner,如下圖,“注冊授權碼”后的字符串便是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的標簽,以區分不同的runner,標簽間逗號分隔
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!

注冊完成便可在上圖中查看你所注冊的Runner。至此,所有安裝完畢,Runner的構建,后續補充。

centos添加gitlab-ce.repo后,需要執行sudo yum makecache

 

參考文章

http://serverfault.com/questions/683196/502-gitlab-is-not-responding-after-change-username

http://skyao.github.io/2015/02/16/git-gitlab-setup/

https://gitlab.com/gitlab-org/omnibus-gitlab/issues/148

http://blog.csdn.net/wangxicoding/article/details/43738137

http://stackoverflow.com/questions/27816046/gitlab-is-not-responding-502-on-ubuntu-14-04-after-starting-server

http://www.cnblogs.com/jasondan/p/4056669.html

http://www.open-open.com/lib/view/open1399684894447.html

http://www.jianshu.com/p/7a0d6917e009

https://xuanwo.org/2016/04/13/gitlab-install-intro/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM