gitlab 從古老的 bitnami 版本 遷移到官方最新版本

 

這是我以前發佈在 yuque 的文章。是我剛來新公司的時候幫公司搬遷 git 記錄下來的,如今看來去掉敏感部分直接發佈也沒啥問題啦,就搬家過來,我本身也方便查 XD .html

8.1.6 -> 10.1.4

首先須要分幾個步驟linux

 

第一步

我將老版本 這裏是從 bitnami gitlab 上安裝的 8.1.4 版本nginx

將這個版本下的全部如今有的數據進行備份。 使用git

 

找到/opt/gitlab-7.x.x-x/apps/gitlab/htdocs/config/gitlab.yml,將backup一項的路徑改成"/data/backups_gitlab",注意目錄的權限更改。redis

這個路徑下面能夠找到咱們的 gitlab 配置文件,將 backup 的地址指定爲咱們想要其備份的地址。spring

以後開始備份,使用數據庫

cd /opt/gitlab-7.x.x-x/
./use_gitlab
cd /opt/gitlab-7.x.x-x/apps/gitlab/htdocs
bundle exec bin/rake gitlab:backup:create RAILS_ENV=production
  • 報錯狀況1:You have already activated rake 0.9.2.2,but our Gemfile requires rake 10.1.0,Using bundle exec may solve this.
    緣由是默認的path路徑不對,須要執行下bitnami自帶的環境變量設置腳本: 執行安裝目錄下use_gitlab 便可解決。 json

  • 報錯狀況2:筆者使用的數據庫爲MySQL,報錯Can't connect to local MySQL server through socket.
    解決方法爲用find指令找到MySQL實際使用的.sock文件,在報錯中的目錄下創建軟連接。centos

 

以後咱們就能在原來的機器上得到一個備份好的壓縮包ruby

這裏注意 backup 的時候不能停機,備份的時候可能會去嘗試連接還在運行的數據庫,若是服務 down 了會連接失敗。

 

第二步

因爲我要到新機器上部署個人新版本,因此我在另一臺機器上下載好了跟以前 bitnami 同樣的版本,這個版本是官方的 Omnibus 版本。我手動下載的 .rpm 包。

我這裏採用手動安裝:

sudo EXTERNAL_URL="http://127.0.0.1:8081" rpm -i gitlab-ee-9.5.2-ee.0.el7.x86_64.rpm

Installing the GitLab Package 

 

With the desired package downloaded, use your systems package management tool to install it. For example:

 

  • DEB based (Ubuntu, Debian, Raspberry Pi): sudo EXTERNAL_URL="http://gitlab.example.com" dpkg -i gitlab-ee-9.5.2-ee.0_amd64.deb

  • RPM based (CentOS, RHEL, Oracle, Scientific, openSUSE, SLES): sudo EXTERNAL_URL="http://gitlab.example.com" rpm -i gitlab-ee-9.5.2-ee.0.el7.x86_64.rpm

 

Change http://gitlab.example.com to the URL at which you want to access your GitLab instance. Installation will automatically configure and start GitLab at that URL.

 

 

[root@iZ2ze9mbirr18cl7fb5ewtZ gitlab]# sudo EXTERNAL_URL="http://git.hundun.cn" rpm -i gitlab-ce-8.1.4-ce.0.el7.x86_64.rpm

gitlab: Thank you for installing GitLab!

gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:

 

sudo gitlab-ctl reconfigure

 

gitlab: GitLab should be reachable at http://iZ2ze9mbirr18cl7fb5ewtZ

gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file

gitlab: And running reconfigure again.

gitlab:

gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme

gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

gitlab:

It looks like GitLab has not been configured yet; skipping the upgrade script.

 

執行 sudo gitlab-ctl reconfigure 會開始配置下載好的 gitlab ,以後咱們就可使用 gitlab-ctl 來執行 gitlab 的 start|end|restart 等等命令了。

 

能夠經過 ps -ef 查看 gitlab 的 nginx 讀取哪兒的配置文件以下:

nginx: master process /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx

因此咱們能夠在 /var/opt/gitlab 下面找到最新的配置文件。

 

Next, install the GitLab package. Change `http://gitlab.example.com` to the URL at which you want to access your GitLab instance. Installation will automatically configure and start GitLab at that URL. HTTPS requires additional configuration after installation.

 

sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ee

其實當咱們在安裝的時候 讓咱們設置的一個地址可讓外部訪問,那個地址會讓 gitlab 自動生成一個 nginx 配置文件,監聽的 server_name 就是咱們設置的地址,若是須要反向代理咱們可能須要去 gitlab 的 nginx 配置目錄下面修改這個監聽地址。若是沒有反向代理,看上去直接設置以後就可使用了(這裏通常都是須要定製的,感受 gitlab 這個也給自動設置有點過於優化了。不過也體現出人家儘可能提高用戶體驗的感受吧)。

 

第三步

拷貝備份到新機器上 這個簡單 scp 一下就好了 like this

scp /home/a.txt root@192.168.0.8:/home/root

從本地 傳輸到 192.168.0.8

 

而後就是 restore

現將以前的複製包 拷貝到 omnibus 版本的 backup 目錄

以後停掉其中兩個服務而且 check 其狀態。

恢復完畢以後讓咱們 check 其狀態。

sudo cp 11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar /var/opt/gitlab/backups/

 

Stop the processes that are connected to the database. Leave the rest of GitLab running:

 

sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq

 

Verify

 

sudo gitlab-ctl status

 

Next, restore the backup, specifying the timestamp of the backup you wish to restore:

 

This command will overwrite the contents of your GitLab database!

這裏會重寫數據庫和內容,由於是恢復備份全部都會清掉因此特地讓咱們注意。

 

sudo gitlab-rake gitlab:backup:restore BACKUP=1493107454_2018_04_25_10.6.4-ce

 

Next, restore /etc/gitlab/gitlab-secrets.json if necessary as mentioned above.

 

Restart and check GitLab:

 

sudo gitlab-ctl restart
sudo gitlab-rake gitlab:check SANITIZE=true

 

If there is a GitLab version mismatch between your backup tar file and the installed version of GitLab, the restore command will abort with an error. Install the correct GitLab version and try again.

這裏特別注意,全部的恢復遷移工做都是創建在備份的版本和安裝的新版本相同的狀況下。

 

第四步

經過官方渠道升級到最新版本。(未完待續)

# Debian/Ubuntu
dpkg -i gitlab-ce-XXX.deb

# CentOS/RHEL
rpm -Uvh gitlab-ce-XXX.rpm

分別使用這兩個包管理工具進行升級。

升級過於老舊的版本須要腳本放得很緩慢,基本上最多 3個 mirror 一升,不然就會出錯。並且是沒法挽回的錯誤又得重來。另外記得每次升級完成後 重啓而後修改 nginx 參數。

完成升級以後能夠留意一下 git 的 host 是否正常。例如若是你使用阿里雲卻不配置對外訪問地址,那麼git host 應該會出現很是奇怪的地址。因此須要配置 gitlab 配置文件將對外地址項改爲域名。而後 gitlab-ctl reconfigure 一下生效便可。

 

雖然這裏記錄的東西最少,可是這裏幾乎最耗時,來來回回包括查資料差很少 8 小時吧。最開始還想一步到位升上去簡直太天真了。

 

以後 linux 下刪除軟件儘可能使用對方提供的現成方法,而且找到全部的刪掉可使用 find 方法。

find / -iname 'xxx'

 

 

 

QA:

 

Q: 卡在卸載gitlab而後再次安裝執行sudo gitlab-ctl reconfigure的時候每每會出現:ruby_block[supervise_redis_sleep] action run,會一直卡沒法往下進行!

A:

一、按住CTRL+C強制結束;

 

二、運行:sudo systemctl restart gitlab-runsvdir;

 

三、再次執行:sudo gitlab-ctl reconfigure

http://www.javashuo.com/article/p-zrucwakb-ge.html

 

Q: 數據庫恢復密碼丟了。

A: https://docs.gitlab.com/ee/security/reset_root_password.html#doc-nav

 

Reference:

https://packages.gitlab.com/app/gitlab/gitlab-ce/search  gitlab 發佈包地址

http://xlindo.com/2015/08/18/gitlab備份與恢復操做方法/  gitlab bitnami 備份恢復文檔

https://community.bitnami.com/t/upgrade-bitnami-gitlab-ce-version/48641  bitnami 官方論壇關於升級問題

https://docs.gitlab.com.cn/omnibus/update/README.html#updating-from-gitlab-66-and-higher-to-the-latest-version  gitlab 官方文檔 -> Updating GitLab via omnibus-gitlab

https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore  restore for Omnibus

https://about.gitlab.com/installation/#centos-7  官方安裝文檔

https://docs.gitlab.com/ee/policy/maintenance.html#versioning  官方推薦升級路徑

https://about.gitlab.com/blog/categories/releases/  官方 relase 文檔

https://www.jianshu.com/p/a86a1529d253  nginx反向代理 gitlab

https://docs.gitlab.com/omnibus/settings/smtp.html  gitlab SMTP settings

相關文章
相關標籤/搜索