GitLabを7にした。ついでにサブディレクトリにした。

Filed in コンピュータ

役割ごとにサーバを分けるようにサーバ構成の見直しをした。
その一環でGitLabを専用サーバに立て直すことにした。

以前はV6を使っていたがせっかくなのでV7にすることにした。
物凄くインストールが楽になっていた。ありがとう。

ただデフォルトだとルートで動いてしまう。つまり以下でアクセスすることになる。
 http://サーバ/

うちのサーバ構成ではnginxをリバースプロキシにしてURLを見てサーバの振り分けをしてるのでこれでは少し具合がわるい。
 http://サーバ/gitlab
にURLを変更することにする。

まずはインストール。以下のとおりにやればOKだ。
 https://about.gitlab.com/downloads/

インストール時のバージョンは7.2.2だったので適宜読み替えで。

$ curl -O http://downloads-packages.s3.amazonaws.com/centos-7.0.1406/gitlab-7.2.2_omnibus-1.el7.x86_64.rpm
$ yum install openssh-server
$ systemctl enable sshd
$ systemctl start sshd
$ yum install postfix
$ systemctl enable postfix
$ systemctl start postfix
$ rpm -i gitlab-7.2.2_omnibus.1-1.el7.x86_64.rpm
$ vi /etc/gitlab/gitlab.rb
external_url 'http://サーバ'     <= なぜかhttp://をつけてくれてないので付ける
$ gitlab-ctl reconfigure
$ firewall-cmd --permanent --add-service=http
$ systemctl reload firewalld

通常ならこれでインストールと起動は完了。非常に楽だ。V6の時に何時間もかけたのは何だったのだろう。。

  http://サーバ でアクセスするとGitLabのログイン画面が表示されるだろう。

さて、このままだとURLがルートのままなので/gitlabに変更する。
/opt/gitlab/embedded/service/gitlab-rails/config/application.rb
に以下ようなやり方が書いてある。これに従えばOKだ。

$ vi /opt/gitlab/embedded/service/gitlab-rails/config/application.rb

冒頭略
    # Relative url support
    # Uncomment and customize the last line to run in a non-root path
    # WARNING: We recommend creating a FQDN to host GitLab in a root path instead of this.
    # Note that following settings need to be changed for this to work.
    # 1) In your application.rb file: config.relative_url_root = "/gitlab"
    # 2) In your gitlab.yml file: relative_url_root: /gitlab
    # 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
    # 4) In ../gitlab-shell/config.yml: gitlab_url: "http://127.0.0.1/gitlab"
    # 5) In lib/support/nginx/gitlab : do not use asset gzipping, remove block starting with "location ~ ^/(assets)/"
    #
    # To update the path, run: sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
    #
    config.relative_url_root = "/gitlab"  <= 1)はここのことだからコメントを外す

2) In your gitlab.yml file: relative_url_root: /gitlab

$ vi /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

冒頭略
   relative_url_root: /gitlab  <=ここ

3) In your unicorn.rb: ENV[‘RAILS_RELATIVE_URL_ROOT’] = “/gitlab”

$ vi /var/opt/gitlab/gitlab-rails/etc/unicorn.rb

最後に追加
ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"

4) In ../gitlab-shell/config.yml: gitlab_url: “http://127.0.0.1/gitlab”

$ vi /var/opt/gitlab/gitlab-shell/config.yml

gitlab_rul: "http:/127.0.0.1:8080/gitlab"

5) In lib/support/nginx/gitlab : do not use asset gzipping, remove block starting with “location ~ ^/(assets)/”
はやらなくてもよいようだ。

サービスを再起動

$ gitlab-ctl stop
$ gitlab-ctl start

さて、これで設定は終わり。
ブラウザでhttp://サーバ/gitlabに繋いでみよう。ログイン画面が表示されるはず。
初期ユーザは以下なので、これでログインする。

Username: root
Password: 5iveL!fe

新しいパスワードの設定を求められるので設定すると、ログイン画面に戻されるので新しいパスワードでもう一度ログインする。
ログイン後にユーザ名もrootから変更しておくといいだろう。

以下おまけ。

最新版では直っているようだが7.2.2の時は/assets下が/gitlab下にならないようである。
そのせいでうちのようにリバースプロキシで/gitlabのアクセスだけをgitlabサーバに振り分けしているとassets下が正しく振り分けられずにアイコンが正しく表示されない。
コードを直してしまうというのもあるが面倒なので以下で対処する。

/assets下もgitlabのサーバに振り分けする。
nginxの場合は以下のようにする。

   location /assets {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header Host $host;
        proxy_pass http://<gitlabサーバ>/assets;
  }

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)