WSLへのGitlab-ce 12.0.0のインストール


動機

  • 家のNUC(2台のubuntu 18.04)にk8sクラスタを作成し、そこにデプロイするアプリのソースはgitlabに入れておきたい
  • NUCに素直に入れてもいいが、そういえばWSLのubuntu 18.04にGitlab入れたことなかったので、試してみた。
  • 動作確認まで至っていないが、reconfigureが通るところまでは行けたので記録を残しておく。

環境

  • Windows10 pro
  • WSL、ubuntu18.04

やったこと

普段Ubuntuで動かすときの手順で入れようとしてみたが、まあ、いろいろハマりますね。。

というわけで、変更している部分について、記録を残しておきます。ちなみに、gitlab-ctl statusで全部起動したように見えても、まだ
「Whoops, GitLab is taking too much time to respond.」
が出ているので、直さないとならないところがあるはず。
(証明書のところが怪しい)

SSL証明書の準備

kura2wsl@Hank:~$ sudo apt-get install -y curl openssh-server ca-certificates
kura2wsl@Hank:~$ openssl genrsa 2048 > hank.localdomain.key
kura2wsl@Hank:~$ openssl req -new -key hank.localdomain.key > hank.localdomain.csr
 → Common Name は hank.localdomain にする
kura2wsl@Hank:~$ openssl x509 -req -days 3650 -signkey hank.localdomain.key < hank.localdomain.csr > hank.localdomain.crt
kura2wsl@Hank:~$ sudo mkdir -p /etc/pki/tls/private
kura2wsl@Hank:~$ sudo mkdir -p /etc/pki/tls/certs
kura2wsl@Hank:~$ sudo cp hank.localdomain.key /etc/pki/tls/private/hank.localdomain.key
kura2wsl@Hank:~$ sudo cp hank.localdomain.crt /etc/pki/tls/certs/hank.localdomain.crt
kura2wsl@Hank:~$ sudo chmod 400 /etc/pki/tls/private/hank.localdomain.key
kura2wsl@Hank:~$ sudo chmod 400 /etc/pki/tls/certs/hank.localdomain.crt

gitlab-ceのインストール

ここで、 ubuntuへのインストール にある以下のGitLab package repository追加の手順を実施しても、その結果生成されるgitlab_gitlab-ce.listを使ってのインストールがうまくいかないことが分かっている。

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash            

gitlab_gitlab-ce.listの中身は以下のように生成される。

kura2wsl@Hank:/etc/gitlab$ cat /etc/apt/sources.list.d/gitlab_gitlab-ce.list
# this file was generated by packages.gitlab.com for
# the repository at https://packages.gitlab.com/gitlab/gitlab-ce

deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ bionic main
deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ bionic main
kura2wsl@Hank:/etc/gitlab$

一見、問題ないようだが、これで以下コマンド打っても
W: The repository 'xxx' does not have a Release file.
のようなリリースファイルが見つからないというメッセージが出て、インストールできない。

kura2wsl@Hank:~$ sudo EXTERNAL_URL="https://hank.localdomain" apt-get install gitlab-ce            

なので、 インストール時に発生する問題のページ を見て以下によりインストールすることにした。

$ curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/bionic/gitlab-ce_12.0.0-ce.0_amd64.deb/download
$ sudo dpkg -i gitlab-ce_12.0.0-ce.0_amd64.deb

結果的に、この手順で以下のメッセージまでは見ることができた。

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

reconfigure

さて、問題のreconfigureである。

gitlab.rbの修正

まず、/etc/gitlab/gitlab.rbを編集する。ポイントは以下。

  • external_urlをhttpsにしておく
  • SSL証明書のファイルパス
  • let's encryptは使っていないのでfalseにしておく。
  • WSLでreconfigureするときにtelinit関連の処理でエラーにならないようdetect_initのところをfalseにする
kura2wsl@Hank:/etc/gitlab$ sudo diff gitlab.rb gitlab.rb.org
13c13
< external_url 'https://hank.localdomain'
---
> external_url 'http://gitlab.example.com'
1013,1014c1013,1014
< nginx['ssl_certificate'] = "/etc/pki/tls/certs/hank.localdomain.crt"
< nginx['ssl_certificate_key'] = "/etc/pki/tls/private/hank.localdomain.key"
---
> # nginx['ssl_certificate'] = "/etc/gitlab/ssl/#{node['fqdn']}.crt"
> # nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/#{node['fqdn']}.key"
1679c1679
< letsencrypt['enable'] = false
---
> # letsencrypt['enable'] = nil
1693c1693
< package['detect_init'] = false
---
> # package['detect_init'] = true
kura2wsl@Hank:/etc/gitlab$

telinitのエラーとは以下のようなエラーのこと。
上記detect_initの変更によりこのエラーを回避している。

Running handlers:
There was an error running gitlab-ctl reconfigure:

execute[init q] (package::runit_sysvinit line 28) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of init q ----
STDOUT:
STDERR: Couldn't find an alternative telinit implementation to spawn.
---- End output of init q ----
Ran init q returned 1

let's encryptはgitlabで使うような設定になっていると、使うための設定とかがされていないもので、以下のようなエラーになる。

Running handlers:
There was an error running gitlab-ctl reconfigure:

letsencrypt_certificate[hank.localdomain] (letsencrypt::http_authorization line 3) 
had an error: Faraday::SSLError: acme_certificate[staging] 
(/opt/gitlab/embedded/cookbooks/cache/cookbooks/letsencrypt/resources/certificate.rb line 20) 
had an error: Faraday::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A

postgresql.confのfsync修正

ファイルの準備はこれだけではない。
postgresqlの処理中に(WSLの問題により、らしいが)以下のようなメッセージが出てエラーになるので、postgresql.confにてfsync = offが必要。

Running handlers:
There was an error running gitlab-ctl reconfigure:

bash[migrate gitlab-rails database] (gitlab::database_migrations line 53) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20190626-24388-11kv27e" ----
STDOUT: rake aborted!
PG::ConnectionBad: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:55:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
Tasks: TOP => gitlab:db:configure
(See full trace by running task with --trace)
STDERR:
---- End output of "bash"  "/tmp/chef-script20190626-24388-11kv27e" ----
Ran "bash"  "/tmp/chef-script20190626-24388-11kv27e" returned 1

postgresqlのログでは以下のように見える。
このメッセージで検索して
http://www.wisesips.com/service/staff_column/197.html
にたどり着いて、対処方法を知ることができた。

kura2wsl@Hank:~$ sudo less /var/log/gitlab/postgresql/current
・・・
2019-06-24_17:02:07.99123 PANIC:  could not flush dirty data: Function not implemented

修正候補のファイルは以下。上2つはcacheのようなのでそれ以外の3ファイルで、「#fsync = on」を、「fsync = off」に修正。

kura2wsl@Hank:/opt/gitlab$ sudo find . |grep postgresql.conf
./embedded/cookbooks/cache/backup/var/opt/gitlab/postgresql/data/postgresql.conf.chef-20190625010711.874519
./embedded/cookbooks/cache/cookbooks/postgresql/templates/default/postgresql.conf.erb
./embedded/cookbooks/postgresql/templates/default/postgresql.conf.erb
./embedded/postgresql/10/share/postgresql.conf.sample
./embedded/postgresql/9.6/share/postgresql.conf.sample
kura2wsl@Hank:/opt/gitlab$ 

runsvdir-startのバックグラウンド実行

何も考えずにreconfigureだけ実行していると、固まる箇所が出てくる。たとえば。

      * link[/opt/gitlab/service/redis] action create
        - create symlink at /opt/gitlab/service/redis to /opt/gitlab/sv/redis
      * ruby_block[wait for redis service socket] action run

このrunが出てからうんともすんとも言わなくなる。

で、これは
https://gitlab.com/gitlab-org/omnibus-gitlab/issues/4257
によると、reconfigureする前に、runsvdir-startをバックグラウンド実行しておけとのこと。

sudo /opt/gitlab/embedded/bin/runsvdir-start &
sudo gitlab-ctl reconfigure

DBの起動やpidファイルでのエラー

以後、どこかでつまづいても上記のrunsvdir-start &と、reconfigureを繰り返すことになるのだが、何度かreconfigureを実行していて、状態が変になってDBでエラー(プロセスが起動していなかったり、起動していてもpidファイルがない等)になることがある。

そのときはgitlab付属のpostgresの状態を調べて必要なら起動や停止をしてやると半端な状態から変えることができ、回復することがある。

kura2wsl@Hank:/etc/gitlab$ sudo gitlab-ctl status
run: gitaly: (pid 4195) 1s; run: log: (pid 31275) 2456s
run: postgresql: (pid 4217) 1s; run: log: (pid 31654) 2443s
run: redis: (pid 30894) 2510s; run: log: (pid 30900) 2509s
kura2wsl@Hank:/etc/gitlab$ 
kura2wsl@Hank:/etc/gitlab$ sudo /opt/gitlab/bin/gitlab-ctl start postgresql
kura2wsl@Hank:/etc/gitlab$ ls -la /var/opt/gitlab/postgresql/
total 0
drwxr-xr-x 1 gitlab-psql root        512 Jun 25 01:53 .
drwxr-xr-x 1 root        root        512 Jun 25 01:41 ..
-rw------- 1 gitlab-psql root         52 Jun 25 01:07 .profile
srwxrwxrwx 1 gitlab-psql gitlab-psql   0 Jun 25 01:53 .s.PGSQL.5432
-rw------- 1 gitlab-psql gitlab-psql  81 Jun 25 01:53 .s.PGSQL.5432.lock
drwx------ 1 gitlab-psql root        512 Jun 25 01:53 data
kura2wsl@Hank:/etc/gitlab$

今の状態

上記で一応reconfigureは通っているのだが、ブラウザで https://hank.localdomain/ にアクセスしても、どうも正常に画面がみれない。
で、/etc/pki配下を見たら以下のようになっていた。証明書が原因かなあ。。

kura2wsl@Hank:/etc/gitlab$ ls -l /etc/pki/tls/private/
total 12
-r-------- 1 root root 1679 Jun 26 01:12 Hank.localdomain.key
-r-------- 1 root root 1679 Jun 26 01:12 Hank.localdomain.key-staging
-r-------- 1 root root 1675 Jun 24 23:29 hank.localdomain.key
kura2wsl@Hank:/etc/gitlab$ ls -l /etc/pki/tls/certs/
total 8
-rw-r--r-- 1 root root 1058 Jun 26 01:12 Hank.localdomain.crt
-r-------- 1 root root 1229 Jun 24 23:29 hank.localdomain.crt
kura2wsl@Hank:/etc/gitlab$

また明日、再チャレンジしてみます。