2016-04-20

安裝與備份Gitlab教學

GitHub幾乎是所有(除了China)資訊工程師置放源碼的首選,但缺點是免費使用你必須開源自己的專案,否則必須額外付費,這時候你可以考慮安裝Gitlab作為repository。

[作業環境]
  • Ubuntu 12.04 LTS
  • Gitlab version:gitlab-ce_7.10.4
[網路環境]
  • 請注意自己的網路有通,不然記得設定proxy
  • export http_proxy=http://${ip}:${port}
  • export https_proxy=http://${ip}:${port}
[安裝步驟]
  • sudo apt-get install curl openssh-server ca-certificates postfix
  • curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
  • sudo apt-get install gitlab-ce=7.10.4~omnibus-1
  • sudo gitlab-ctl reconfigure
[Gitlab網頁設定]
  • 把自己的IP替換這兩個檔案
    • sudo vim /etc/gitlab/gitlab.rb
    • sudo vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
  • 重啟Gitlab
    • sudo gitlab-ctl reconfigure
    • sudo gitlab-ctl restart
[備份]
  • 透過指令會把當下時間的檔案完整備份到/var/opt/gitlab/backups成一個tar檔,可能是1461088867_gitlab_backup.tar
    • sudo gitlab-rake gitlab:backup:create
  • 修改備份路徑
    • vim /etc/gitlab/gitlab.rb
    • 設定 gitlab_rails['backup_path'] = '${backup_path}'
[設定自動備份]
  • 設定crontab
    • sudo crontab -e
  • 新增crontab指令
    • 設定每天凌晨1點進行備份
    • 0 1 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
  • 順便設定一下遠端備份
    • 0 2 * * * rsync -av --delete -e ssh /var/opt/gitlab/backups/*.* ${account}@${ip}:/var/opt/gitlab/backups/
[將備份還原]
  • 暫停既有服務
    • gitlab-ctl stop unicorn 
    • gitlab-ctl stop sidekiq
  • 設定權限,否則會報錯
    • chown git:git 1461088867_gitlab_backup.tar
  • 重啟服務
    • sudo gitlab-ctl start
[注意事項]
  • 備份還原只允許同版本的Gitlab

沒有留言:

張貼留言