Bitnami 版本的 GitLab 升級

首先,先備份資料(廢話)

這裡的 mysql 密碼請使用 bitnami 的帳號密碼,詳細可以參考:
cat /opt/$bitnami/apps/gitlab/htdocs/config/database.yml | grep password

底下的$PATH_TO_BACKUP請自行替換成備份路徑,然後$bitnami替換成對應的版本路徑,例如gitlab-6.0.0-0
cd /opt/$bitnami
sudo ./use_gitlab
cd /opt/$bitnami/mysql/bin/
mysqldump -u bitnami -p bitnami_gitlab > $PATH_TO_BACKUP/bitnami_gitlab_bk.sql
mysqldump -u bitnami -p bitnami_gitlabci > $PATH_TO_BACKUP/bitnami_gitlabci_bk.sql
mkdir $PATH_TO_BACKUP/git
mkdir $PATH_TO_BACKUP/gitlab_ci
cp -r /home/git/.ssh $PATH_TO_BACKUP/git/.ssh
cp -r /home/gitlab_ci/.ssh $PATH_TO_BACKUP/gitlab_ci/.ssh
mv /opt/$bitnami/apps/gitlab/repositories $PATH_TO_BACKUP/

執行完以上的備份工作之後就是把舊版本移除(可選擇性移除舊有檔案,建議移除省空間),並且安裝新版本

安裝完之後,使用以下指令開始轉移舊資料($bitnami為新版本路徑):
cd /opt/$bitnami
sudo ./ctlscript.sh stop
sudo ./ctlscript.sh start mysql
sudo ./use_gitlab
mysql -u root -p

然後在mysql中執行以下SQL指令(底下的password請替換成新版本提供的密碼,請使用前方所述的找密碼指令來找到現在的密碼 ):
drop database bitnami_gitlab;
drop database bitnami_gitlabci;
create database bitnami_gitlab;
create database bitnami_gitlabci;
grant all privileges on bitnami_gitlab.* to 'bitnami'@'localhost' identified by 'password';
grant all privileges on bitnami_gitlab.* to 'gitlab'@'localhost' identified by 'password';
grant all privileges on bitnami_gitlabci.* to 'bitnami'@'localhost' identified by 'password';
grant all privileges on bitnami_gitlabci.* to 'gitlab'@'localhost' identified by 'password';
flush privileges;
\q

隨後繼續以下指令
mysql -u root -p bitnami_gitlab < $PATH_TO_BACKUP/bitnami_gitlab_bk.sql
mysql -u root -p bitnami_gitlabci < $PATH_TO_BACKUP/bitnami_gitlabci_bk.sql
cp -r $PATH_TO_BACKUP/git /home
cp -r $PATH_TO_BACKUP/gitlab_ci /home
rm -rf /opt/$bitnami/apps/gitlab/repositories
mv $PATH_TO_BACKUP/repositories /opt/$bitnami/apps/gitlab
chown -Rf git:git /home/git/.ssh
chown -Rf gitlab_ci:gitlab_ci /home/gitlab_ci/.ssh
chmod -R g+rwX /opt/$bitnami/apps/gitlab/repositories
chown -Rf git:git /opt/$bitnami/apps/gitlab/repositories
cd /opt/$bitnami/apps/gitlab/htdocs
bundle install --deployment --without development test postgres --binstubs
cd /opt/$bitnami/apps/gitlabci/htdocs
ruby bin/rake db:migrate RAILS_ENV=production
cd /opt/$bitnami/apps/gitlab/htdocs
ruby bin/rake db:migrate migrate_iids RAILS_ENV=production
/opt/$bitnami/ctlscript.sh restart
ruby bin/rake assets:clean assets:precompile cache:clear RAILS_ENV=production
cd /opt/$bitnami/
./ctlscript.sh restart

完成轉移,最後記得修改 /home/git/.ssh/authorized_keys 的 command 變數,將裡面原本的路徑更新即可,不然 runner 會不能跑。
以及移除舊的shell script宣告,該行在git與gitlab_ci帳號的.profile噢.bashrc中,不然會有錯誤導致不能重啟服務。
另外,若要啟用https,但是登入不了且發現log裡面有
Can't verify CSRF token authenticity
此類錯誤的話,請在下列的設定檔中,參考官方conf檔案加入
RequestHeader set X_FORWARDED_PROTO 'https'
到下列這些檔案的適當位置即可。

  • /opt/$bitnami/apps/gitlab/conf/httpd-app.conf
  • /opt/$bitnami/apps/gitlabci/conf/httpd-app.conf
另外,如果有任何的問題的話,可以執行下面這行來檢查是否有問題,並且根據訊息來修正即可:
ruby bin/rake gitlab:check RAILS_ENV=production

ref: http://wiki.bitnami.com/Applications/BitNami_GitLab#General_procedure_to_upgrade_the_stack
ref: https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/
ref: https://gitlab.com/gitlab-org/gitlab-recipes/blob/master/web-server/apache/gitlab-ssl.conf

留言

熱門文章