LoginSignup
9
16

More than 3 years have passed since last update.

0からGitlab-CEを立ち上げてPagesを公開するまで

Last updated at Posted at 2019-08-21

はじめに

公式ドキュメント
意外と公式ドキュメント通りにやってる手順がなかったので、やってみた。

下準備

検証用インスタンス立ち上げ

今回はGCPでCentOS7のGCEインスタンスを立ち上げて、Gitlabインストールする。
(諸事情によりバージョン11.11.8で試しています)

$ sudo yum update
$ sudo yum install -y curl policycoreutils-python openssh-server
$ sudo systemctl enable sshd
$ sudo systemctl start sshd
$ sudo firewall-cmd --permanent --add-service=http
$ sudo systemctl reload firewalld
$ sudo yum install postfix
$ sudo systemctl enable postfix
$ sudo systemctl start postfix
$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
$ sudo yum --showduplicates search gitlab-ce | grep 11.11.8
gitlab-ce-11.11.8-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
$ sudo yum install gitlab-ce-11.11.8-ce.0.el7.x86_64
$ sudo vi /etc/gitlab/gitlab.rb
(external_url 'http://xxx.xxx.xxx.xxx/' GIPを設定)
$ sudo gitlab-ctl reconfigure

とりあえず、アクセスできる事を確認。

Gitlab Pagesプロジェクト作成

お試しプロジェクトを作成する。

  1. New Projectボタンをポチッと押す。
  2. Create from templateからPagesPlain HTMLUse templateをポチる。

スクリーンショット 2019-08-21 16.53.01.png
3. 適当に名前をつけてCreate projectを押す。

スクリーンショット 2019-08-21 16.59.30.png
できた。

Gitlab Runner有効化

CI環境が必須なので有効化する。

  1. Gitlabプロジェクトの設定からCI/CDを選択。
  2. Runnersセクションを広げる。
  3. URLtokenを控える。

スクリーンショット 2019-08-21 17.35.00.png
4. CentOSにてもう一台GCEインスタンスを作成。

$ sudo yum update
$ curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
$ sudo yum install gitlab-runner
$ sudo yum install docker

$ sudo systemctl start docker
$ sudo systemctl enable docker
$ sudo systemctl start gitlab-runner
$ sudo systemctl enable gitlab-runner

$ sudo gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=6360 revision=de7731dd version=12.1.0
Running in system-mode.                            

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://xxx.xxx.xxx.xxx/ ← 控えたURL
Please enter the gitlab-ci token for this runner:
xxxxxxxxxxxxxxxxxxxx ← 控えたtoken
Please enter the gitlab-ci description for this runner:
[hori-test-gitlab-runner]: 
Please enter the gitlab-ci tags for this runner (comma separated):
          ← とりあえずタグは未指定(そのままEnter)
Registering runner... succeeded                     runner=UhtBLpGi
Please enter the executor: custom, docker, docker-ssh, shell, virtualbox, parallels, ssh, docker+machine, docker-ssh+machine, kubernetes:
docker
Please enter the default Docker image (e.g. ruby:2.6):
centos:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 

Gitlabコンソールで確認すると追加されてる。
スクリーンショット 2019-08-21 17.01.11.png

Pages有効化

DNSの設定

お使いのDNSにて、先ほど作ったGitlabのGIPとドメインのAレコードを追加。

  • ワイルドカードドメインとGIPの例
    • *.pages.hogehoge.work
    • 35.241.261.50

設定ファイル変更

Gitlabインスタンスでの作業。

  1. /etc/gitlab/gitlab.rb の下記のみ編集
    • pages_external_url "http://pages.hogehoge.work/"
    • gitlab_pages['enable'] = true
  2. sudo gitlab-ctl reconfigure
  3. sudo gitlab-ctl restart

デプロイ

Gitlabコンソールのプロジェクト内で作業。

  1. CI/CDPipelinesを開く。
  2. Run Pipelineを押す。
  3. もういちどRun Pipelineを押す。
  4. 少し待つとpassed表示になり、デプロイ成功。
  5. SettingsPagesにURLがあるのでクリック。
  6. Pages表示される!! スクリーンショット 2019-08-21 17.55.55.png

SSL対応

専用にワイルドカード証明書が必要。(お高い)
ここの例だと、*.pages.hogehoge.workを買ってください。

設定方法

Gitlabインスタンスでの作業。

  1. 証明書hoge.crtを用意。
  2. 中間証明書intermediate.crtを用意。
  3. cat hoge.crt intermediate.crt >> /etc/gitlab/ssl/hogehoge.crtを実行。
  4. 秘密鍵hoge.key/etc/gitlab/ssl/以下にコピー。
  5. /etc/gitlab/gitlab.rbの下記のみ編集
    • pages_external_url "https://pages.hogehoge.work/" ←httpsに変更した。
    • pages_nginx['enable'] = true
    • pages_nginx['redirect_http_to_https'] = true
    • pages_nginx['ssl_certificate'] = "/etc/gitlab/ssl/hogehoge.crt"
    • pages_nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/hoge.key"
  6. sudo gitlab-ctl reconfigure
  7. sudo gitlab-ctl restart

おわりに

お金がなくて証明書買えなかったので、次回は12にバージョンアップしてLet's EncryptでSSL化を試したい。

9
16
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
9
16