4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Gitlab(13.12) のインストール [ Apache Subdirectry 運用 ]

Last updated at Posted at 2021-05-15

インストール 作業メモ [21/07/04]

Apache Subdirectry 運用設定

  • Ubuntu 20.04.2 LTS
  • GitLab CE Edition v13.12.6 (Omnibusパッケージ)
  • ruby 2.7.2p137
  • Rails 6.0.3.6
  • PostgreSQLは、 GitLabに同梱されているものが標準設定で使用されます。[12.6]
 経路としては、 WAN → apache[SSL設定] → Gitlab付属のnginx[8080ポート] の設定になります。 

※私の設定では、apache側でSSL設定を行っています。
※エンタープライズ版(EE)でも構わないと説明はありますが、オープンソース版と明示されている
 CommunityEdition (GitLab CE) をインストールしています。 


image.png

・インストール設定内容

  インストール先:   /opt/gitlab, /etc/gitlab, /var/opt/gitlab
  ユーザー & グループ: www-data : www-data
  設定ファイル :    /etc/gitlab/gitlab.rb
  設定アドレス(ダミー): https://gitlab.example.com/gitlab/


①サブディレクトリ用の追加設定[Apacheの設定]

※先にApacheの設定をダミーの状態で進めます。
default-ssl.conf に追記しました。ポート番号は適時変更します。

/etc/apache2/sites-available/default-ssl.conf
<VirtualHost _default_:443>
 --------

 <Location /gitlab>
  Require all granted
  ProxyPassReverse http://127.0.0.1:8080
  ProxyPassReverse https://gitlab.example.com/gitlab/

  RewriteEngine on

  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
  RewriteCond %{REQUEST_URI} ^/uploads/.*
  RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA,NE]
 </Location>

--------
</VirtualHost>

・apache 再起動コマンド

以下のコマンドで、先にApacheを動かしておきます。以降、無事にGitLabの設定が完了すれば
[https://gitlab.example.com/gitlab/] にてGitlabが起動します。

sudo a2ensite gitlab
sudo apache2ctl configtest
sudo systemctl restart apache2
sudo systemctl reload apache2   ※↑もしくはこちら

②Gitlabプログラムのダウンロード、展開、配置

https://packages.gitlab.com/gitlab/gitlab-ce
 から "ubuntu/focal" のパッケージを探します。

https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/focal/gitlab-ce_13.12.6-ce.0_amd64.deb
(特に説明はないのですが、Omnibusパッケージです。)
image.png

以下のコマンドで、初期インストールが完了します。

sudo apt-get install gitlab-ce=13.12.6-ce.0

↑インストール完了後、自動起動設定まで完了します。

③設定ファイルの編集

※必要な項目を修正します。

↓さらに詳しい説明はこちら
https://docs.gitlab.com/omnibus/settings/README.html

/etc/gitlab/gitlab.rb
external_url 'http://gitlab.example.com/gitlab/'   #32行
gitlab_rails['time_zone'] = 'Asia/Tokyo'           #68行
nginx['listen_port'] = 8080                        #1369行
letsencrypt['enable'] = nil                     #2235行

※Let's Encryptを利用して証明書が発行される仕組みがありますすが
 私のケースでは使用しません。

設定ファイルの変更後は以下のコマンドを実行し、反映させます。

sudo gitlab-ctl diff-config    ※変更箇所のチェックコマンド
sudo gitlab-ctl stop        ※Gitlabを一旦止めます。
sudo systemctl stop gitlab-runsvdir  ※念の為、一旦止めます。
sudo systemctl start gitlab-runsvdir  ※これは起動していないと駄目みたいです。
sudo gitlab-ctl reconfigure       ※上記設定ファイルの反映
sudo gitlab-ctl restart         ※Gitlabの再起動 この後数分待つ必要があります。

ちなみに、初回のreconfigureは、私の環境では5分程度かかりました。
image.png

④起動確認

[https://gitlab.example.com/gitlab/] にアクセスして確認します。
数分程、待つ必要があります。
 1.初期画面では、rootユーザーのパスワードを設定します。
image.png

 2.上記画面で設定したパスワードを使用し、rootユーザーでログインします。
image.png

 3.以下の様な初期画面が表示されます。
image.png


④その他

■GitLab 自動起動の仕組み

インストール時に以下の設定が行われ、起動はこのプログラムが担当します。
場所:/lib/systemd/system/gitlab-runsvdir.service

systemctl enable gitlab-runsvdir

■注① 502エラーで焦ってしまう件

sudo gitlab-ctl restart コマンドの後などで、以下のエラーになる時があります。
大抵は、設定変更後の処理に時間がかかるらしく、数分待てば直ります。
ここで焦って、すぐに設定を変えたりすると、さらにハマります。

image.png

■注② reconfigureが途中で止まる件

reconfigureが途中で止まるトラブルに遭遇しました。
結局、電源を再起動し、以下のコマンドでreconfigureが可能になりました。

sudo gitlab-ctl stop
sudo systemctl stop gitlab-runsvdir
sudo systemctl start gitlab-runsvdir  ※←これが起動していないと駄目みたいです。
sudo gitlab-ctl reconfigure

■gitlab-ce アンインストール用のコマンド

sudo gitlab-ctl stop
sudo systemctl stop gitlab-runsvdir

sudo apt-get remove gitlab-ce
sudo rm -rf /etc/gitlab
sudo rm -rf /opt/gitlab
sudo rm -rf /var/opt/gitlab
■参考にさせていただいたページ

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?