LoginSignup
7
7

More than 5 years have passed since last update.

gitlabを移行(ソース>Ommunibus、6.8>8.11、mysql>postgresql、CentOS6>7)した話

Last updated at Posted at 2016-09-28

gitlabのバージョンアップと移行をということでやりました。
その備忘録です。
6.8から8.11にupかつソースmysqlからommunibusのpostgresqlにコンバート
(CentOS6から7にも上げているがAMIをPackerでつくったりchefっている詳細は割愛。)

めっちゃながいです。メンテ6時間くらい。

バージョンアップは基本的にはこの辺からたどると大体書いてあるとおりです。
https://github.com/gitlabhq/gitlabhq/tree/master/doc/update

旧環境と新環境の情報

旧:
CentOS6
apache+passenger,mysql,redis,git,gitlab6.8,ldap認証

新:
CentOS7
ommunibus gitlab(nginx,redis,postgresql等ぜんぶいりで別に入れる必要がない)
暗号化、認証まわりは同様に設定する必要がある。

特記事項:
・バージョン変わるごとに毎回dbマイグレーションしているようで、
 異なるバージョンどうしでmysqldumpで復旧はできない仕様。

・ソース版だとバージョンアップの手間がかかるので運用が楽になるのを見越してommunibus版にする。
 mysqlからpostgresqlになるのでデータのコンバートが必要。
 mysqlにしてたのはRDS使いたかったせい。冗長性を楽に実現できるMultiAZにしたい。
 いまはpostgresqlのRDSもあるのでそれをつかう。

・CentOS6->7でかわるなと思ったのは主に以下(gitlabはほぼ関係ない)
 systemdになる(serviceからsystemctlになるけどchef的に意識不必要、host名変更がオプション指定で永続化でべんり)
 ntpdが標準でなくなるが代わりのはうるう秒のバースト更新的な挙動があやういのでntpdつかうのがいい気がしている
 apacheが2.4標準になってアクセス制御の記述の仕方とロードモジュールとかの設定ファイルの構造がかわる
 あとはパッと思い出せない。

0.マイグレ環境の下準備をする

・AMIとってマイグレーション環境を複製する

先にgitlabにログインして以下を打つ

$ sudo chkconfig gitlab off

AMIはコンソールからno_rebootでとる(先に更新できないように旧サーバを丸ごと止めといてもいいかも
AMIができたらそこから起動したのもをマイグレーション環境とし
ログインする
(バージョンアップとデータのコンバートをすすめる環境)

# aws ec2 describe-security-groups --filters Name=group-name,Values=SG_xxxxxx --profile xxxxx
# aws ec2 describe-instances --instance-ids i-xxxxx --profile xxxxx

本移行用は最新AMIをとってインスタンス起動する
(旧世代でHVMではなかったのでm4とか使えなかったはず)

aws ec2 run-instances \
--profile xxxx \
--image-id ami-xxxxxx \
--count 1 \
--key-name hogexxxx \
--security-group-ids sg-xxxxxx sg-xxxxxx \
--instance-type m3.large \
--placement AvailabilityZone=us-xxxx-xa,Tenancy=default \
--monitoring Enabled=false \
--subnet-id subnet-xxxxxxx \
--associate-public-ip-address

newip=
ssh user@${newip}

gitlabが停止していることを確認する

$ netstat -lnpt
$ ps -ef
$ sudo service gitlab status

コピー元と区別するためにhost名を変更する

$ sudo hostname gitlab-test   ##名前違えばなんでもいいがhostsも併せて変える
$ bash
$ uname -n

hostsを編集して自分が本物のgitlabだと認識させておく

$ sudo vi /etc/hosts

10.124.0.xxx    gitlab-test   gitlab  gitlab.xxxx.xxxx.xxxxx.net localhost

旧gitlabのはコメント化する。

・RDSのmysqldumpをとってローカルdbに投入、database.ymlを編集しDB接続をローカルに変える

mysqlを起動

$ sudo vi /etc/my.cnf
必要があれば設定ファイルを適当に直す(起動しなかったらエラーログみて直す)
$ sudo service mysql start
$ sudo view /var/log/mysqld/mysqld.log

rakeでバックアップとろうとすると以下エラーがでるのでシンボリックリンクを貼る
(または/etc/my.cnfのsocket=を修正してmysqlを再起動する)

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

$ sudo ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

本番からsingle-transactionでデータをダンプしてローカルにいれる

$ mysqldump -u gitlab -p -h hoge-gitlab-rds.mng.hoge.local --databases gitlabhq_production --quote-names --opt --single-transaction --hex-blob -R > /tmp/mysqldump-`date +%Y%m%d`.sql
$ mysql -u gitlab -p --default-character-set=utf8 < /tmp/mysqldump-`date +%Y%m%d`.sql

アカウントまわりを一応確認する

$ pt-show-grants -u root -p

データベースの設定ファイルを編集してgitlabから認識される先をローカルに変える

$ sudo vi /home/git/gitlab/config/database.yml
  host: hoge-gitlab-rds.mng.hoge.local
   ↓
  host: localhost

たぶんサービス起動停止以外はgitユーザで作業。

1.6.xから7.14へバージョンアップ

・rakeでbackupをとる(使わないが念のため

$ sudo su - git
$ cd gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production

$ ls -lh tmp/backups/
-rw-r--r-- 1 git git 705M  3月  5 15:17 2015 1425568606_gitlab_backup.tar
$ df -h;df -i

・rubyを入れる

mkdir /tmp/ruby && cd /tmp/ruby
curl --progress https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.6.tar.gz | tar xz
cd ruby-2.1.6
./configure --disable-install-rdoc
make -j 2
sudo make install

$ /usr/local/bin/gem environment

いろいろPATHを通しておく

$ sudo su - git
$ vi ~/.bashrc
export PATH=/usr/local/bin:/opt/chef/embedded/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/ruby/2.1.0:$LD_LIBRARY_PATH
export RUBYLIB=/usr/local/lib/ruby/2.1.0:$RUBYLIB

$ vi ~/.gemrc 
gempath:
- /usr/local/lib/ruby/2.1.0
gem: --no-rdoc --no-ri

$ bash
$ gem env

・bundler入れる

$ sudo /usr/local/bin/gem install bundler --no-ri --no-rdoc

gitlabはとまってるのでそのままバージョンアップ作業をすすめる

・7系のgitlabにチェックアウト

$ sudo su - git
$ cd /home/git/gitlab
$ git fetch --all

$ git checkout -- db/schema.rb
$ git checkout 7-14-stable

・必要なパッケージ入れる

$ sudo yum install logrotate cmake nodejs libkrb5-dev pkg-config

・redisをunixソケット使うようにする

$ sudo service redis stop
$ sudo cp -p /etc/redis.conf{,.org}
$ sudo vi /etc/redis.conf
$ diff /etc/redis.conf{,.org} 
72,73c72
< unixsocket /var/run/redis/redis.sock
< unixsocketperm 775
---
> # unixsocketperm 755
$ sudo service redis start

・gitユーザのサブグループにredisを追加

$ sudo usermod -aG redis git
$ id git
uid=1001(git) gid=1001(git) 所属グループ=1001(git),494(redis)

$ sudo su - git
$ cd gitlab
$ cp config/resque.yml.example config/resque.yml
$ cat config/resque.yml

$ vim /home/git/gitlab-shell/config.yml
  socket: /var/run/redis/redis.sock

・gitlab-shellを合うバージョンにチェックアウトする

$ cd /home/git/gitlab-shell
$ git fetch
$ git checkout v2.6.5

・インストール(mysqlの場合)

$ cd /home/git/gitlab
$ /usr/local/bin/bundle install --without development test postgres --deployment

・# Enable internal issue IDs (introduced in GitLab 6.1)
$ /usr/local/bin/bundle exec rake migrate_iids RAILS_ENV=production

rougeの以下のようなエラーがでたらGemfile.lock編集してrougeを1.10.0に修正すると出なくなるけど出ても別に作業すすまないこともないしcheckoutでなおさないとpull失敗するので無視して大丈夫

/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/rouge-1.9.1/lib/rouge/lexers/shell.rb:20: warning: already initialized constant Rouge::Lexers::Shell::KEYWORDS
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/rouge-1.9.1/lib/rouge/lexers/shell.rb:20: warning: previous definition of KEYWORDS was here
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/rouge-1.9.1/lib/rouge/lexers/shell.rb:25: warning: already initialized constant Rouge::Lexers::Shell::BUILTINS

・dbをマイグレ

$ /usr/local/bin/bundle exec rake db:migrate RAILS_ENV=production

・プレコンパイル

$ bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production

$ chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites

$ ls -dl /home/git/gitlab-satellites
drwxr-x--- 6 git git 4096  8月 19 08:40 2016 /home/git/gitlab-satellites

$ cp -p /etc/init.d/gitlab{,.`date +%Y%m%d-1`}
$ cp lib/support/init.d/gitlab /etc/init.d/gitlab

・設定

$ vi config/gitlab.yml

コメント以外のところを修正。gitlab.ymlはこの段階でなおさなくても別に大丈夫。

$ git diff 6-8-stable:config/unicorn.rb.example 7-14-stable:config/unicorn.rb.example

-worker_processes 2
+worker_processes 3

-listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64
+listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 1024

-timeout 30
+timeout 60

$ vi config/unicorn.rb

$ cd ../gitlab-shell/
$ cat VERSION 
$ git diff v1.9.4:config.yml.example v2.6.5:config.yml.example

+  # pass: redispass # Allows you to specify the password for Redis
+  database: 0
+  socket: /var/run/redis/redis.sock # Comment out this line if you want to use TCP

 # Log file.
@@ -39,3 +55,11 @@ log_level: INFO

+git_annex_enabled: false

$ vi config.yml
$ cd ../gitlab

$ diff config/initializers/rack_attack.rb{,.example}
$ cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

・起動

$ sudo service gitlab start

以下のようなエラーが出たらymlのシンタックスエラーなのでtypoをみなおす。

Psych::SyntaxError: (<unknown>): did not find expected key while parsing a block mapping at line 129 column 4

エラーがどうにもならなかったら設定ファイルのバックアップとってから新バージョンのサンプルと見比べながら修正する

もしapacheがおちてたら起動

$ sudo service httpd start

・環境情報確認とテスト

$ sudo su - git
$ cd gitlab
$ bundle exec rake gitlab:env:info RAILS_ENV=production

$ bundle exec rake gitlab:check RAILS_ENV=production

Send ping to redis server: Could not connect to Redis at /var/run/redis/redis.socket: No such file or directory
gitlab-shell self-check failed
  Try fixing it:
  Make sure GitLab is running;
  Check the gitlab-shell configuration file:
  sudo -u git -H editor /home/git/gitlab-shell/config.yml
  Please fix the error above and rerun the checks.

vim /home/git/gitlab-shell/config.yml
/var/run/redis/redis.socket
↓
/var/run/redis/redis.sock

・dbのALTER等をマニュアルどおりやる

マニュアルどおり本体はとめとく

$ sudo service gitlab stop

$ mysql -u gitlab -p

6.8から必要そうなのを選んで実施。

mysql> use gitlabhq_production
mysql> SELECT CONCAT('ALTER TABLE gitlabhq_production.', table_name, ' ENGINE=InnoDB;') AS 'Copy & run these SQL statements:' FROM information_schema.tables WHERE table_schema = 'gitlabhq_production' AND `ENGINE` <> 'InnoDB' AND `TABLE_TYPE` = 'BASE TABLE';
mysql> SET foreign_key_checks = 0;
mysql> SELECT CONCAT('ALTER TABLE gitlabhq_production.', table_name, ' CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;') AS 'Copy & run these SQL statements:' FROM information_schema.tables WHERE table_schema = 'gitlabhq_production' AND `TABLE_COLLATION` <> 'utf8_unicode_ci' AND `TABLE_TYPE` = 'BASE TABLE';
mysql> SET foreign_key_checks = 1;
mysql> show grants for 'gitlab'@'localhost';

・gitlabを起動してログイン確認をする、helpでバージョンが上がっていることを確認

gitlabを起動する

$ sudo service gitlab start

gitlab.mng.hoge.example.netをローカルPCのhostに登録してブラウザから見てみる。

"PublicIpAddress"を確認

$ aws ec2 describe-instances --instance-ids i-xxxxxxxx --profile xxxx
or
$ curl -s http://169.254.169.254/latest/meta-data/public-ipv4

ブラウザでhelpからバージョンが上がっていることを確認

2.7.14から8.0へバージョンアップ

・gitlabを止める

$ sudo service gitlab stop

・rakeでbkupしようとしたら権限がたらなかったらしいので付与

Dumping MySQL database gitlabhq_production ... mysqldump: Got error: 1044: Access denied for user 'gitlab'@'localhost' to database 'gitlabhq_production' when using LOCK TABLES

$ mysql -u root -p
mysql> GRANT LOCK TABLES ON gitlabhq_production.* TO 'gitlab'@'localhost';
mysql> FLUSH PRIVILEGES;

・rakeでbackupをとる

$ sudo su - git
$ cd gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production
$ ls -lh tmp/backups/

-rw-rw-r-- 1 git git 1.9G  9月 14 07:32 2016 1473838054_gitlab_backup.tar
-rw------- 1 git git 1.9G  9月 15 01:10 2016 1473901803_gitlab_backup.tar

・gitのバージョンを上げる

$ /usr/local/bin/git --version
git version 1.9.0

依存パッケージをupdateする

$ sudo yum install libcurl-devel libxslt-devel libxml2-devel expat-devel gettext openssl-devel zlib-devel

sudo wget https://www.kernel.org/pub/software/scm/git/git-2.9.3.tar.gz -P /usr/local/src
cd /usr/local/src/
sudo tar zxf git-2.9.3.tar.gz
cd /usr/local/src/git-2.9.3
sudo ./configure --prefix=/usr/local/git
sudo make all
sudo make install

$ /usr/local/bin/git --version
git version 2.9.3

・バージョンアップ作業をすすめる

・8.0のgitlabにチェックアウト

latestだと8-11-stableだったっぽいがメジャーバージョンが上がるのは段階を踏まないと危険そうなので8.0のコードにcheckoutする

$ sudo su - git
$ cd gitlab

    rougeを無理やり上げずにエラー無視の場合は以下不要
    $ git checkout  Gemfile.lock
$ git fetch --all
$ git checkout db/schema.rb
$ git checkout 8-0-stable

・Goを入れる

curl --remote-name --progress https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.5.linux-amd64.tar.gz
sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
rm go1.5.linux-amd64.tar.gz
$ which go

・gitlab-git-http-serverは入れずにgitlab-workhorseを入れて最新にする(replaceとupdateの手間をはぶく)

sudo su - git
$ cd /home/git
git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
cd /home/git/gitlab-workhorse
git fetch --all
git checkout v0.7.11
make

$ cd /home/git/gitlab
$ git checkout 8-2-stable
$ git diff 8-0-stable:lib/support/init.d/gitlab.default.example 8-2-stable:lib/support/init.d/gitlab.default.example
$ exit
$ sudo cp -p /home/git/gitlab/lib/support/init.d/gitlab.default.example /etc/default/gitlab
$ view /etc/default/gitlab

けっこうちがうようなので起動スクリプトをコピーしておく
(8.2の起動スクリプトでないとworkhouseが起動しないので8-2-stableにcheckoutした状態でコピー)

$ exit
$ sudo cp -p /etc/init.d/gitlab{,.714.bk}
$ sudo cp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab
$ sudo cp -p /etc/init.d/gitlab{,.80.bk}

$ sudo su - git
$ cd gitlab
$ git checkout 8-0-stable

・データベースの鍵情報が必要になるらしいので追加しておく

# cp config/secrets.yml.example config/secrets.yml
# chmod 0600 config/secrets.yml
# chown git. /home/git/gitlab/config/secrets.yml    ###オーナーがgitでないとdb:migrateしっぱいする。
# vi config/secrets.yml
  db_key_base: **********

sudo su - git
cd gitlab
$ bundle install --without postgres development test --deployment
$ bundle exec rake db:migrate RAILS_ENV=production

$ bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production

diff lib/support/init.d/gitlab /etc/init.d/gitlab

・gitlabを起動してログイン確認をする、helpでバージョンが上がっていることを確認

サーバ起動

$ sudo service gitlab start

$ sudo su - git
$ cd gitlab
$ bundle exec rake gitlab:env:info RAILS_ENV=production

チェックの前に権限修正、

chmod 0750 /home/git/gitlab/public/uploads
 mkdir /home/git/gitlab/public/uploads/tmp
find /home/git/gitlab/public/uploads -type d -not -path /home/git/gitlab/public/uploads -exec chmod 0755 {} \;
ls -lh /home/git/gitlab/public/uploads

チェック

$ bundle exec rake gitlab:check RAILS_ENV=production

Init script up-to-date? ... no になるけどさらに新しくしてるだけで起動してるので問題なし

とりあえずブラウザで確認。
バージョンが8.05になってることを確認

3.8.0から8.11へバージョンアップ

・rakeでbackupをとる(念のため)

bundle exec rake gitlab:backup:create RAILS_ENV=production
$ ls -lh tmp/backups

-rw------- 1 git git 1.9G  9月 15 02:09 2016 1473905330_gitlab_backup.tar

・gitlabを止める

$ sudo service gitlab stop

・バージョンアップ作業をすすめる

$ sudo su - git
$ cd gitlab
$ pwd
/home/git/gitlab

・Update Ruby

$ cd /tmp/ruby
curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar xzf ruby-2.3.1.tar.gz
cd ruby-2.3.1
./configure --disable-install-rdoc
make
sudo make install

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

ライブラリのパスを通す(/usr/local/lib/ruby/2.3.0)

$ sudo su - git
$ vi ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/ruby/2.3.0:$LD_LIBRARY_PATH
export RUBYLIB=/usr/local/lib/ruby/2.3.0:$RUBYLIB
$ vi ~/.gemrc
gempath:
- /usr/local/lib/ruby/2.3.0
gem: --no-rdoc --no-ri
$ gem env gempath

sudo su -

gitと同じようにpathをとおす、bundlerを入れる

$ bash
$ sudo /usr/local/bin/gem install bundler --no-ri --no-rdoc

・チェックアウト

$ cd gitlab
$ git checkout -- db/schema.rb
$ git checkout 8-11-stable
$ git branch

・Update gitlab-shell

cd /home/git/gitlab-shell
$ git fetch --all --tags
git checkout v3.4.0

・インストールとマイグレートとプレコンパイルとキャッシュクリア、起動スクリプトコピー。

cd /home/git/gitlab
$ bundle install --without postgres development test --deployment
$ bundle clean
$ bundle exec rake db:migrate RAILS_ENV=production
$ bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production

$ sudo cp -p /etc/init.d/gitlab{,.8.2}
$ sudo cp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab

・設定比較,修正

$ sudo su - git
$ cd gitlab
$ git diff origin/8-0-stable:config/gitlab.yml.example origin/8-11-stable:config/gitlab.yml.example
$ cp -p config/gitlab.yml{,.80}
$ cp -p config/gitlab.yml.example config/gitlab.yml
$ vim config/gitlab.yml
$ vim config/gitlab.yml.80
見比べながらなおす
$ diff config/gitlab.yml{,.example}
32,34c32,34
<     host: gitlab.mng.hoge.example.net
<     port: 443 # Set to 443 if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
<     https: true # Set to true if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
---
>     host: localhost
>     port: 80 # Set to 443 if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
>     https: false # Set to true if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
70c70
<     email_from: gitlab@mng.hoge.example.com
---
>     email_from: example@example.com
215c215
<     enabled: true
---
>     enabled: false
235c235
<         host: '10.xxx.xxx.xxx'
---
>         host: '_your_ldap_server'
237,238c237
<         #uid: 'sAMAccountName'
<         uid: 'uid'
---
>         uid: 'sAMAccountName'
240,241c239,240
<         bind_dn: 'uid=Auth,ou=System,dc=hoge,dc=example,dc=net'
<         password: '******'
---
>         bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
>         password: '_the_password_of_the_bind_user'
251c250
<         active_directory: false
---
>         active_directory: true
262c261
<         allow_username_or_email_login: true
---
>         allow_username_or_email_login: false
273c272
<         base: 'dc=hoge,dc=example,dc=net'
---
>         base: ''
282c281
<         user_filter: ""
---
>         user_filter: ''
480c479
<     bin_path: /usr/local/bin/git
---
>     bin_path: /usr/bin/git

・smtpまわり

$ cp -p config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb
$ vi config/initializers/smtp_settings.rb

いちおうローカルにつなぐ体で修正

$ diff config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb
15,22c15,22
<     address: "email.server.com",
<     port: 465,
<     user_name: "smtp",
<     password: "123456",
<     domain: "gitlab.company.com",
<     authentication: :login,
<     enable_starttls_auto: true,
<     openssl_verify_mode: 'peer' # See ActionMailer documentation for other possible options
---
>     address: "localhost",
>     port: 25,
>     user_name: "git",
>     password: "",
>     domain: "gitlab.mng.hoge.example.net",
> #    authentication: :login,
>     enable_starttls_auto: false,
> #    openssl_verify_mode: 'peer' # See ActionMailer documentation for other possible options

$ sudo cp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab

$ sudo chmod 700 /home/git/gitlab/public/uploads
$ sudo find /home/git/gitlab/public/uploads -type f -exec chmod 0644 {} \;
$ sudo find /home/git/gitlab/public/uploads -type d -not -path /home/git/gitlab/public/uploads -exec chmod 0700 {} \;

$ sudo cp -p /home/git/gitlab-shell/config.yml{,.80}
$ sudo vim /home/git/gitlab-shell/config.yml
$ vim /home/git/gitlab-shell/config.yml.example 

みくらべていらないの消すなど修正する

$ sudo diff /home/git/gitlab-shell/config.yml{,.80}
18c18
< #repos_path: "/home/git/repositories"
---
> repos_path: "/home/git/repositories"

unicorn一応確認

$ cp -p config/unicorn.rb{,.80}
$ diff config/unicorn.rb{,.80}
39c39
< listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 1024
---
> listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64
43c43
< timeout 60
---
> timeout 30

起動しなかったら/home/git/gitlab/logのしたのログをみる(大体パースエラーなのでサンプルコピーして編集推奨)

・gitlabを起動してログイン確認をする、helpでバージョンが上がっていることを確認

$ sudo service gitlab start
$ service httpd restart
$ sudo su - git
$ cd gitlab

$ bundle exec rake gitlab:env:info RAILS_ENV=production
$ bundle exec rake gitlab:check RAILS_ENV=production

ブラウザからみる
https://gitlab.mng.hoge.example.net/help
なんか8.11.7になってマイナーバージョンが上がってたので事前に修正してあったchefリポジトリのパッケージバージョンをなおすなど。

4.mysqlからpostgresqlへコンバート

・gitlabを止める

$ sudo service gitlab stop

・rakeでbackupをとる

$ sudo su - git
$ cd gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production
$ ls -lh tmp/backups/
-rw------- 1 git git 1.9G  9月 15 04:50 2016 1473915031_gitlab_backup.tar


$ bk_prefix=1473915031 ##★lsの結果を変数に入れる

・pythonのバージョンを2.7以上にする

$ python -V 
Python 2.6.6
$ cd /usr/local/src
$ sudo curl -O https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz 
$ sudo tar zxf Python-2.7.12.tgz 
$ cd Python-2.7.12
$ sudo ./configure
$ sudo make
$ sudo make install

$ which python
/usr/local/bin/python
$ /usr/local/bin/python -V
Python 2.7.12

・コンバートツールでコンバートする

$ sudo su - git
cd gitlab
$ mkdir -p tmp/backups/postgresql
$ cp tmp/backups/${bk_prefix}_gitlab_backup.tar tmp/backups/postgresql/

diskが足らなくなるのでここで不要な古いbackupは消す。

$ df -h
$ ls -lh /home/git/gitlab/tmp/backups
$ rm -f /home/git/gitlab/tmp/backups/1425568606_gitlab_backup.tar
$ rm -f /home/git/gitlab/tmp/backups/1425914208_gitlab_backup.tar
$ df -h
$ ls -lh /home/git/gitlab/tmp/backups

$ sudo su - git
$ cd tmp/backups/postgresql
$ mysqldump --compatible=postgresql --default-character-set=utf8 -r gitlabhq_production.mysql -u root gitlabhq_production -p
Enter password: 
$ ls

$ git clone https://github.com/gitlabhq/mysql-postgresql-converter.git -b gitlab
$ ls

$ mkdir db
$ python mysql-postgresql-converter/db_converter.py gitlabhq_production.mysql db/database.sql
$ ed -s db/database.sql < mysql-postgresql-converter/move_drop_indexes.ed

アーカイブする

$ gzip db/database.sql
$ ls db
database.sql.gz

・同名のmysqlのアーカイブデータと入れ替える

$ tar tf ${bk_prefix}_gitlab_backup.tar
$ tar rf ${bk_prefix}_gitlab_backup.tar db/database.sql.gz

立てたらomunibusのgitlabにコンバート済みバックアップを転送する

$ newgitlab=
$ bk_prefix=
$ sudo scp -Cp /home/git/gitlab/tmp/backups/postgresql/${bk_prefix}_gitlab_backup.tar user@${newgitlab}:/tmp/

5.postgresqlのRDSを用意、パラメータグループ調整

スペックはdb.t2.largeに確定

http://qiita.com/awakia/items/9981f37d5cbcbcd155eb
http://dev.classmethod.jp/cloud/aws/rds-postgres-log-settings/
http://tdoc.info/blog/2012/07/09/postgres_tuning.html
https://www.postgresql.org/docs/9.5/static/runtime-config-logging.html

gitlab-postgres-9-5等の名前でpostgresql9.5用に作成

デフォルト値等を確認。

SELECT name,setting,unit FROM pg_settings;
log_min_duration_statement = 250ms
log_temp_files = 0
log_checkpoints = 1
log_lock_waits = 1
log_connections = 1
log_disconnections = 1

shared_buffers instanceタイプごとに勝手に調整されるので気にしないことにする
work_mem 32768 デフォ4096kbだったので32MBからはじめるらしいので増やす
maintenance_work_mem instanceタイプごとに勝手に調整されるので気にしないことにする
effective_cache_size instanceタイプごとに勝手に調整されるので気にしないことにする
random_page_cost 2 4だとおおきいらしいので2にする
synchronous_commit 決済を扱うDBではないが落ちたときに危ないからいじらない

postgresql用security_group更新または作成する必要がある。

$ aws ec2 describe-security-groups --filters Name=group-name,Values=SG_xxxxxx --profile xxxx
RDSを作成する
    aws rds create-db-instance \
    --profile hoge \
    --db-name gitlabhq_production \
    --db-instance-identifier hoge-gitlab-rds \
    --storage-type gp2 \
    --allocated-storage 100 \
    --db-instance-class db.t2.large \
    --engine postgres \
    --engine-version 9.5 \
    --master-username gitlab \
    --master-user-password 'xxxxx***' \
    --db-security-groups sg-xxxxxxxx \
    --availability-zone us-xxxx-xa \
    --db-subnet-group-name xxxxxxxx \
    --db-parameter-group-name gitlab-postgres-9-5 \
    --preferred-maintenance-window "tue:14:00-tue:14:30" \
    --preferred-backup-window "18:00-18:30" \
    --backup-retention-period 7 \
    --port 5432 \
    --multi-az \
    --no-auto-minor-version-upgrade \
    --no-publicly-accessible
※cliでうまくいかずマネジメントコンソールにて同様の作業を実施。

エンドポイントをchefリポジトリに登録済みの名称でroute53のプライベートゾーンに登録しておく
Muliti-AZで切り替わったとき用にttlは60でCNAMEで登録する

で、gitlab同梱のposgresqlのバージョンがOS標準と同じ9.2でRDSで使えるバージョンが9.3~9.5とかだったので、それだとrailsでバックアップが不可能なエラーが出たので、

$ sudo gitlab-rake gitlab:backup:create
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... pg_dump: server version: 9.5.2; pg_dump version: 9.2.18
pg_dump: aborting because of server version mismatch
[FAILED]
Backup failed

9.5のクライアント入れて/etc/gitlab/gitlab.rbのPATHの順序を調整しました。

$ sudo yum install https://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/postgresql95-libs-9.5.4-2PGDG.rhel7.x86_64.rpm
$ sudo yum install https://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/postgresql95-9.5.4-2PGDG.rhel7.x86_64.rpm
$ which psql
/usr/bin/psql
$ psql --version
psql (PostgreSQL) 9.5.4

$ sudo diff /etc/gitlab/gitlab.rb{,.`date +%Y%m%d`}
~略~
247,248c247,248
<   'PATH' => "/usr/bin:/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin" 
< }
---
> #   'PATH' => "/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin:/usr/bin" 
> # }

6.CentOS7かつommunibus gitlab8.11の新環境を構築

nginxのhttps、ldap認証、smtpは送信のみ等

作っておいたAMIとレシピでたてました。詳細は割愛。
/etc/gitlab/gitlab.rbの差分だけ置いときます。

$ sudo diff /var/chef/backup/etc/gitlab/gitlab.rb.chef-20160915082044.674309 /etc/gitlab/gitlab.rb 
11c11
< external_url 'http://ec2-xxxxxxx.us-xxxx-2.compute.amazonaws.com'
---
> external_url 'https://gitlab.mng.hoge.example.net/'
21,24c21,24
< # gitlab_rails['time_zone'] = 'UTC'
< # gitlab_rails['gitlab_email_enabled'] = true
< # gitlab_rails['gitlab_email_from'] = 'example@example.com'
< # gitlab_rails['gitlab_email_display_name'] = 'Example'
---
> gitlab_rails['time_zone'] = 'UTC'
> gitlab_rails['gitlab_email_enabled'] = true
> gitlab_rails['gitlab_email_from'] = 'gitlab@mng.hoge.example.net'
> gitlab_rails['gitlab_email_display_name'] = 'Gitlab'
59c59
< # gitlab_rails['incoming_email_enabled'] = true
---
> gitlab_rails['incoming_email_enabled'] = false
107,127c107,127
< # gitlab_rails['ldap_enabled'] = false
< # gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' # remember to close this block with 'EOS' below
< #   main: # 'main' is the GitLab 'provider ID' of this LDAP server
< #     label: 'LDAP'
< #     host: '_your_ldap_server'
< #     port: 389
< #     uid: 'sAMAccountName'
< #     method: 'plain' # "tls" or "ssl" or "plain"
< #     bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
< #     password: '_the_password_of_the_bind_user'
< #     active_directory: true
< #     allow_username_or_email_login: false
< #     block_auto_created_users: false
< #     base: ''
< #     user_filter: ''
< #     attributes:
< #       username: ['uid', 'userid', 'sAMAccountName']
< #       email:    ['mail', 'email', 'userPrincipalName']
< #       name:       'cn'
< #       first_name: 'givenName'
< #       last_name:  'sn'
---
> gitlab_rails['ldap_enabled'] = true
> gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' # remember to close this block with 'EOS' below
>   main: # 'main' is the GitLab 'provider ID' of this LDAP server
>     label: 'LDAP'
>     host: 'ldap1.mng.hoge.local'
>     port: 389
>     uid: 'uid'
>     method: 'plain' # "tls" or "ssl" or "plain"
>     bind_dn: 'uid=Auth,ou=System,dc=hoge,dc=example,dc=net'
>     password: '************'
>     active_directory: 'false'
>     allow_username_or_email_login: 'true'
>     block_auto_created_users: false
>     base: 'dc=hoge,dc=example,dc=net'
>     user_filter: ''
>     attributes:
>       username: ['uid', 'userid', 'sAMAccountName']
>       email:    ['mail', 'email', 'userPrincipalName']
>       name:       'cn'
>       first_name: 'givenName'
>       last_name:  'sn'
247,248c247,248
<   'PATH' => "/usr/bin:/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin" 
< }
---
> #   'PATH' => "/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin:/usr/bin" 
> # }
281,283c281,283
< # gitlab_rails['db_username'] = "gitlab"
< # gitlab_rails['db_password'] = nil
< # gitlab_rails['db_host'] = nil
---
> gitlab_rails['db_username'] = "gitlab"
> gitlab_rails['db_password'] = '*******'
> gitlab_rails['db_host'] = 'gitlab-db-psql.mng.hoge.local'
322,323c322,323
< # gitlab_rails['smtp_address'] = "smtp.server"
< # gitlab_rails['smtp_port'] = 465
---
> gitlab_rails['smtp_address'] = "elb-int-smtp.mng.hoge.local"
> gitlab_rails['smtp_port'] = 25
326c326
< # gitlab_rails['smtp_domain'] = "example.com"
---
> gitlab_rails['smtp_domain'] = "mail.mng.hoge.example.net"
509d508
< # postgresql['log_line_prefix'] = "%a"
511d509
< # postgresql['shared_preload_libraries'] = nil
570d567
< 
573c570
< # nginx['redirect_http_to_https'] = false
---
> nginx['redirect_http_to_https'] = true
576c573
< # nginx['ssl_verify_client'] = "off" # enable/disable 2-way SSL client authentication
---
> nginx['ssl_verify_client'] = "off" # enable/disable 2-way SSL client authentication
578,579c575,576
< # nginx['ssl_certificate'] = "/etc/gitlab/ssl/#{node['fqdn']}.crt"
< # nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/#{node['fqdn']}.key"
---
> nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.mng.hoge.example.net.crt"
> nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.mng.hoge.example.net.key"
593,599c590,596
< # nginx['proxy_set_headers'] = {
< #  "Host" => "$http_host",
< #  "X-Real-IP" => "$remote_addr",
< #  "X-Forwarded-For" => "$proxy_add_x_forwarded_for",
< #  "X-Forwarded-Proto" => "https",
< #  "X-Forwarded-Ssl" => "on"
< # }
---
> nginx['proxy_set_headers'] = {
>   "Host" => "$http_host",
>   "X-Real-IP" => "$remote_addr",
>   "X-Forwarded-For" => "$proxy_add_x_forwarded_for",
>   "X-Forwarded-Proto" => "https",
>   "X-Forwarded-Ssl" => "on"
>  }
603,604c600
< # nginx['real_ip_trusted_addresses'] = []
< # nginx['real_ip_header'] = nil
---
> nginx['real_ip_trusted_addresses'] = ['10.xxx.xxx.0/20']# nginx['real_ip_header'] = nil

nginxをsslでつかうためには証明書を所定のディレクトリにcommonネーム.{crt,key}というような感じに置いとかないと認識されなかったのが罠っぽかったです。
ldapはsecondary指定するとエラーでてた。あとldapのCA証明書つかうtls認証は公式サポート外風。
⇒そのご、method:がtlsじゃなくてsslなら証明書検証せずに暗号化通信可能、ということがわかりました。

ssh 10.xxx.xxx.xxx

chefの実行状況を見守る。
出来上がったらローカルPCのhostsをだましてログインしてみる。
修正の関係で元のgitlabを見たい場合はDNSキャッシュをクリアするか元のgitlabをローカルPCのhostsに明示的に書く
(windowsならipconfig /flushdnsする)

$ sudo vim /etc/hosts

あとhostsのデータをchefリポジトリ修正してコミット。

7.コンバート済みのバックアップを新環境にレストアする

omunibus-gitlabでレストアする

$ newgitlab=
$ ls /tmp
$ bkup_prefix=
$ ssh user@${newgitlab}
$ sudo cp /tmp/${bkup_prefix}_gitlab_backup.tar /var/opt/gitlab/backups/
$ sudo chown -R git. /var/opt/gitlab/backups
$ sudo gitlab-ctl stop unicorn
$ sudo gitlab-ctl stop sidekiq
$ sudo gitlab-rake gitlab:backup:restore BACKUP=${bkup_prefix}
$ sudo gitlab-ctl start

$ sudo chmod -R ug+rwX,o-rwx /var/opt/gitlab/git-data/repositories
$ sudo chmod -R ug-s /var/opt/gitlab/git-data/repositories
$ sudo find /var/opt/gitlab/git-data/repositories -type d -print0 | sudo xargs -0 chmod g+s
$ sudo -u git -H /opt/gitlab/embedded/service/gitlab-shell/bin/create-hooks /var/opt/gitlab/git-data/repositories

$ sudo gitlab-rake gitlab:check

ここでログインできるかを確認(Standard/LDAP)。

メールが自分に届くかをmailコマンドで確認
(gitlabからはlocalhostに向けていてpostfixが別のMTAにリレーしてるレシピを前からchefってあるので特に手作業はなし)

$ echo test-komi |mail -s new-gittest test@fuga.co.jp

8.DNSを切り替えEIPを付け替える、動作を確認する

まずhostsを切り替えて確認、
問題なさそうであればグローバルのレコードを修正

gitlab.mng.hoge.example.net をローカルIPに修正(VPN越しにつなぐのでプライベートIP)

EIP を旧gitlabからはずして新gitlabにつける

pullしてみたり更新したリポジトリをpushするなど

  問題があって切り戻す場合は止めといた旧サーバを起動する。DNSとかEIPとか変えてたら戻す。

それと、jenkins的なCIツール連携してる場合はそこからの接続の認識をドメイン以外のIPとかで直に指定してしまってる場合とかssh的なknown_hostsまわりのエントリを差し替えるとかをしないといけなかったですね。
jenkinsだと以下のかんじでした。

$ sudo vi /etc/hosts
domainはdigで解決できるのでhostsから削除

10.xxx.xxx.xxx   gitlab  gitlab.mng.hoge.example.net
↓
10.xxx.yyy.zzz    gitlab  

いちおうjenkinsリスタート
$ sudo service jenkins restart

ssh/configをなおす

$ sudo vi /var/lib/jenkins/config
$ sudo vi /var/lib/jenkins/.ssh/config

HostName gitlab.mng.hoge.example.net    ##直IPだったのでドメインに直す

known_hosts消して入れなおす
$ sudo vi /var/lib/jenkins/.ssh/known_hosts
$ sudo su - jenkins
$ ssh gitlab.mng.hoge.example.net
実際ログインしなくてもknown_hostsにはかかれる

gitlabからjenkinsに向けた通信でWebhookのssl verificationを個別のプロジェクトで外す

もしgitlabからcloneできない場合はそのサーバでhttp.sslverifyをfalseにする
$ sudo su - jenkins
$ git config --global http.sslverify false
か
$ vi /var/lib/jenkins/.gitconfig
[http]
        sslverify = false

今後のommunibus-gitlab-ceバージョンアップ方法

リポジトリ追加

curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
yum repolist

yumコマンドでバージョンアップ

sudo yum update gitlab-ce
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

参考情報

バージョンアップ関連
https://wiki.archlinux.org/index.php/Gitlab#Redis_Over_Unix_Socket
http://docs.gitlab.com/ce/install/installation.html#initial-login
https://github.com/gitlabhq/gitlabhq/issues/6100
http://interprism.hatenablog.com/entry/gitlab6to8
http://d.hatena.ne.jp/akishin999/201308
http://qiita.com/nobuhito/items/7df5f9eb550c300999ff
https://gitlab.com/gitlab-org/gitlab-recipes/blob/master/web-server/apache/gitlab-ssl-apache24.conf
https://github.com/gitlabhq/gitlabhq/tree/master/doc/update
https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/7.14-to-8.0.md
https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/8.0-to-8.1.md
https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/8.1-to-8.2.md
https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/8.8-to-8.9.md
https://github.com/gitlabhq/gitlabhq/blob/master/doc/update/8.10-to-8.11.md

Ommunibus参考
https://rythgs.co/archives/2015/10/31/switch-omnibus-gitlab/
http://qiita.com/int512/items/632adb4d0b02439d1a9c
http://qiita.com/hosopy/items/965a34d59a0d46731f7c
https://about.gitlab.com/downloads/#centos7

rubyまわり(環境変数とかでPATHがとおってない的な混乱があった)
http://docs.ruby-lang.org/ja/2.0.0/library/rubygems.html
http://d.hatena.ne.jp/zariganitosh/20141016/minimum_making_of_gem

pythonのバージョンアップ
https://gitlab.com/gitlab-org/gitlab-ce/blob/52e903e99f3b220553e65be7b6034dfbaeef6d81/doc/update/mysql_to_postgresql.md
https://www.python.org/ftp/python/
http://qiita.com/Hiroyama-Yutaka/items/8a52d54819a0923436a7

nginx関連
http://next49.hatenadiary.jp/entry/20141114/p2
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md#supporting-proxied-ssl
http://qiita.com/TaskeHAMANO/items/b01f2d8590c23d6b2bce

httpsまわり
http://mudanakaigi.blogspot.jp/2013/10/gitlab.html

ldaps関連(TLSできない問題)
⇒そのご、method:がtlsじゃなくてsslなら証明書検証せずに暗号化通信可能、ということがわかりました。
https://docs.gitlab.com/ce/administration/auth/ldap.html
http://stackoverflow.com/questions/18984198/how-to-debug-gitlab-ldap-authentication
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/ldap.md
http://stackoverflow.com/questions/24457408/openssl-command-to-check-if-a-server-is-presenting-a-certificate
https://gitlab.com/gitlab-org/omnibus-gitlab/issues/712
https://gitlab.com/gitlab-org/omnibus-gitlab/issues/1370
https://gitlab.com/gitlab-org/gitlab-ce/issues/1168
http://simosan.minibird.jp/wordpress/openldap/openldap%E3%81%AEssltls%E8%A8%AD%E5%AE%9A/
http://stackoverflow.com/questions/21477210/correct-location-of-openssl-cnf-file
https://gitlab.com/gitlab-org/gitlab-ce/issues/13669

postgresql関連(コンバートとパラメータグループ調整)
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/update/mysql_to_postgresql.md#converting-a-gitlab-backup-file-from-mysql-to-postgres
http://qiita.com/awakia/items/9981f37d5cbcbcd155eb
http://dev.classmethod.jp/cloud/aws/rds-postgres-log-settings/
http://qiita.com/Morihaya/items/d09f6f41ba3c374b8cc2
http://db.just4fun.biz/PostgreSQL/%E3%82%AF%E3%83%A9%E3%82%A4%E3%82%A2%E3%83%B3%E3%83%88%E5%81%B4%E3%81%AE%E3%81%BF%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E6%96%B9%E6%B3%95.html
http://tdoc.info/blog/2012/07/09/postgres_tuning.html
https://www.postgresql.org/docs/9.5/static/runtime-config-logging.html

改善された点と残り

・apache+passengerのようなのやソースのバージョンアップであるような手間のかかる更新がいらなくなった
・設定ファイルが一元化した

・ldapsのTLS認証ができなかった(現状解決手段がなさそうなので今後の課題
⇒そのご、method:がtlsじゃなくてsslなら証明書検証せずに暗号化通信可能、ということがわかりました。なーんだ。
・postgresqlのチェックするポイントになるログ出しておきながら監視の仕組みをつくれてない
・rakeでの定期バックアップの実装について、IAMロールは、'use_iam_profile' => true,とか書くといける模様。
 サブディレクトリというかpathを指定して置くのはなんだかできないぽいので以下のようなs3 syncとかで。
 サブディレクトリいらない場合は定期削除はバケットのライフサイクルでよさそう。

# cat /opt/bin/s3backup-gitlab.sh
#!/bin/bash
#
# s3 backup script for local gitlab.
# see: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md#backups
DATE=`date +%Y%m%d`
WEEK=`date +%w`
BK_DIR=/var/opt/gitlab/backups
LOG=/opt/bin/bk.log
S3URL=s3://<mybucket-name>/backup/hoge-git01
export AWS_CONFIG_FILE=/root/.aws/config

## daily backup.
echo "`date +%Y%m%d.%H%M%S` aws s3 backup start." >> ${LOG}
cd ${BK_DIR}/
aws s3 sync . ${S3URL} --delete --acl private --exclude "*" --include "*_gitlab_backup.tar" --profile hoge
echo "`date +%Y%m%d.%H%M%S` aws s3 backup end." >> ${LOG}

exit

おわりです。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7