前の記事にわかりにくい箇所や、「sudo -u git -H bundle exec rake…」について記載していなかったりしたので、改めてここにまとめなおします。
構築内容は以下の通り。
- Fornt EndとしてApache(http:80番ポート, https:443番ポート)で動作。他のポートからのアクセスは許さない。
- GitLabへは/gitlabでアクセス。
- /gitlabでアクセスした場合
- httpならhttpsへredirectする。
- httpsならGitLabにバンドルされているnginxの8000番ポート(localhost, Non-Secure)へReverseProxyする。
- Gravatarは使用しない。
- 登録したAvatarアイコンが表示されない問題については解決しない。(後日記載する。)
GitLabのInstall
gitlabのrpmは事前にgitlab公式サイトから取得しておく。
$ sudo rpm -i gitlab-7.2.0_omnibus-1.el6.x86_64.rpm Thank you for installing GitLab! You can configure GitLab for your system by running the following command: sudo gitlab-ctl reconfigure
gitlab-ctl reconfigureしろと書いているが、先にgitlab.rb(/etc/gitlab/gitlab.rb)を修正する。
# Change the external_url to the address your users will type in their browser external_url 'http://<HostName>:8000' gitlab_rails['gravatar_enabled'] = false
gravatar_enabledをfalseで設定することでGravatar機能をオフにできる。
修正が完了したらreconfigureを実行。だいたい以下のような感じで出力される。
$ sudo gitlab-ctl reconfigure Starting Chef Client, version 11.12.2 (中略) Chef Client finished, 109/142 resources updated in 102.146198253 seconds gitlab Reconfigured!
サブディレクトリで運用するための設定
/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
1)2)はコメントアウトを外す。3)はENV[‘RAILS_…] = “/gitlab”を追加する。4)はURLに/gitlabを追加。5)はnginxの設定ファイルからlocationのブロックを削除する。
修正するファイルは以下の通り。
- /opt/gitlab/embedded/service/gitlab-rails/config/application.rb
- /var/opt/gitlab/gitlab-rails/etc/gitlab.yml
- /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
- /var/opt/gitlab/gitlab-shell/config.yml
- /var/opt/gitlab/nginx/etc/gitlab-http.conf
最後に「sudo -u git …」を実行しPathをUpdateする。内容がbundleとrakeであるため、それっぽいファイルのある/opt/gitlab/embedded/service/gitlab-railsへ事前に移動しておく。
$ cd /opt/gitlab/embedded/service/gitlab-rails $ ls *file Gemfile Guardfile Procfile Rakefile
コマンドを実行すると以下の結果が返ってきた。
$ sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production Gemfile syntax error compile error on line 20: syntax error, unexpected ':', expecting $end gem "mysql2", group: :mysql
Gemfileの文法エラーで失敗。環境的に何かが悪いらしい。が、それを特定せずともrakeを実行することは可能。
$ sudo gitlab-rake assets:precompile RAILS_ENV=production [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. I, [2014-08-24T19:06:49.155011 #11237] INFO -- : Writing /opt/gitlab/embedded/service/gitlab-rails/public/assets/authbuttons/github_32-199ebcd7adccbfe20068d39bfd57e6bf.png (中略) I, [2014-08-24T19:09:45.851492 #11237] INFO -- : Writing /opt/gitlab/embedded/service/gitlab-rails/public/assets/emoji/yellow_heart-dea623f0ba60659e82bcde41bd75dfd6.png
httpdの設定
/etc/httpd/conf/httpd.confを修正する。http://<HostName>/gitlabでアクセスした場合、https://<HostName>/gitlabへRedirectする。
<VirtualHost *:80> (中略) RewriteEngine on SSLProxyEngine on RewriteCond %{REQUEST_URI} ^/gitlab RewriteCond %{HTTPS} !=on RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R] </VirtualHost>
<VirtualHost *:443>の設定はhttpd.confか他の適切なconfファイルに行うこと。(/etc/httpd/conf.d/ssl.confとか。)
<VirtualHost *:443> (中略) SSLCertificateFile <Server証明書ファイルへのPath> SSLCertificateKeyFile <Server秘密キーファイルへのPath> (中略) RewriteEngine on SSLProxyEngine on RewriteCond %{REQUEST_URI} ^/gitlab RewriteRule (.*) http://127.0.0.1:8000%{REQUEST_URI} [P] </VirtualHost>
https://<HostName>/gitlabの場合はhttp://127.0.0.1:8000/gitlabへReverseProxyする。Server証明書ファイルや秘密キーファイルはOpenSSLなどで適当に作成すること。
サービスの起動及びログイン
GitLabとhttpdを開始する。
$ sudo gitlab-ctl start ok: run: nginx: (pid 11267) 0s ok: run: postgresql: (pid 11271) 1s ok: run: redis: (pid 11279) 0s ok: run: sidekiq: (pid 11283) 1s ok: run: unicorn: (pid 11286) 0s $ sudo service httpd restart httpd を停止中: [ OK ] httpd を起動中: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [ OK ]
http://<HostName>/gitlabでアクセスしログイン画面が表示できていれば概ね完了。あとはid/pw → root/5iveL!feを入力し設定を進めていく。
Avatarアイコンの問題
サブディレクトリで運用するとAvatarアイコンをUploadした場合、Avatarアイコンが表示できない問題が発生した。この件に関しては後日、対策内容を記載する。
では。