Git 是一種分布式的代碼版本管理系統,git在工作時可以不用時刻依賴后台服務器,在本地電腦上就可以管理版本控制,但是在需要協同開發時就必須要使用后台服務器了,目前互聯網上有github,碼雲這樣的遠程代碼庫可以使用,但是對於企業來說,自己的核心代碼還是放在企業內部比較安全。
Gitlab 是一款開源的git代碼版本管理系統的后台服務器,在一個生產代碼的企業里,這樣的服務器是必不可少的,下面就來探討一下如何搭建企業gitlab服務器。
1. 根據官方安裝文檔安裝相應的包
sudo yum install -y curl policycoreutils-python openssh-server cronie sudo lokkit -s http -s ssh
第二條命令:允許通過http和ssh方式訪問gitlab
2. 手動下載gitlab-ce安裝包
下載地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-11.9.8-ce.0.el6.x86_64.rpm
3. 安裝gitlab-ce
rpm -ivh gitlab-ce-11.9.8-ce.0.el6.x86_64.rpm
出現上面的界面表明gitlab-ce安裝完成
4. 漢化
漢化包下載地址:https://gitlab.com/xhang/gitlab/tree/11-9-stable-zh
本次安裝的gitlab版本是V11.9.8,那就下和這個版本一樣的漢化包
wget https://gitlab.com/xhang/gitlab/-/archive/11-9-stable-zh/gitlab-11-9-stable-zh.tar.gz
解壓漢化包
tar -xzvf gitlab-11-9-stable-zh.tar.gz
備份英文版本
cp -r/opt/gitlab/embedded/service/gitlab-rails{,.bak}
覆蓋英文版本
cd gitlab-11-9-stable-zh cp -rf */opt/gitlab/embedded/service/gitlab-rails/
5. 配置gitlab.rb
Gitlab的配置文件:/etc/gitlab/gitlab.rb
修改這個配置文件,修改如下內容行:
egrep -v '#' /etc/gitlab/gitlab.rb |egrep -v '^$' external_url 'http://xytgit' gitlab_rails['backup_keep_time'] = 31536000 user['username'] = "git" user['group'] = "git" unicorn['listen'] = '192.168.10.21' unicorn['port'] = 8088 nginx['listen_port'] = 80
說明:
第一行:配置訪問URL
第二行:備份保存時間
第三行:gitlab運行用戶
第四行:gitlab運行用戶組
第五行:unicorn監聽地址 unicorn是ruby寫的httpserver
每六行:unicorn監聽端口
第7行:gitlab自帶nginx監聽端口
6. 運行gitlab-ctl reconfigure
報了如下的錯,意思是說創建鏈接文件tmp時,發現已存在一個叫tmp的目錄,因此無法創建一個叫tmp的鏈接,仔細檢查漢化目錄發現的確存在一個tmp的目錄,解決方法是刪除tmp目錄。
除了tmp,還有一個log目錄也同樣需要刪除,否則無法創建鏈接文件
7. 啟動gitlab服務
Gitlab-ctl start
8. 查看gitlab服務狀態
Gitlab-ctl status
9. 登錄gitlab主頁
10. 502錯誤解決方法
發生502錯誤,基本上都是因為端口被占用,修改合適端口即可。
Gitlab-ctl reconfigure
Gitlab-ctl restart
11. Gitlab數據備份
gitlab-rake gitlab:backup:create
數據備份的目錄在/etc/gitlab/gitlab.rb配置文件中有定義
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
12. Gitlab數據恢復
先停止相關服務
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
例如我們的備份文件的編號是1502357536_2017_08_10_9.4.3,因此執行下面的命令即可恢復gitlab
gitlab-rake gitlab:backup:restore BACKUP=1502357536_2017_08_10_9.4.3
敲完命令后,出現第一個交互頁面,
# gitlab-rake gitlab:backup:restore BACKUP=1502357536_2017_08_10_9.4.3 Unpacking backup ... done Before restoring the database we recommend removing all existing tables to avoid future upgrade problems. Be aware that if you have custom tables in the GitLab database these tables and all data will be removed. Do you want to continue (yes/no)?
輸入yes即可恢復。