CentOS 7にGitHubライクなオンプレミス GitLab CE (community edition) を2分でインストール・導入・構築してみた

Git

GitのWebインターフェースを探している中で、GitWeb、Ginatraを試したのですが、イマイチでした。

GitWebが日本語でエラー出すので、Ginatra(ギナトラ)のインストール手順をまとめた
GitWebが日本語でエラー出すので、Ginatraをインストールしてみました。 Ginatraのインストール手順をまとめました。 GitWebで日本語のhistoryをクリックするとThis page contains the ...

 

そこで今回、GitLabを試してみました。

 

GitLabは、単にGitのGUIインターフェースのみならず、ユーザー管理、グループ管理、リポジトリのバックアップなどを行うユーザーインターフェースを備え、いわばリポジトリの管理システムとなっています。

 

スポンサーリンク

GitLab (ギットラボ) とは

GitLab (公式サイト: https://about.gitlab.com/ ) は、

wikiとバグ管理機能(Issue Tracking System)を備えたGitのリポジトリ管理システムです。

GitLabの読み方は、ギットラボです。

 

クラウドサービスである GitHubと似ていますが、GitLabの場合、オンプレミスな自社サーバーに導入出来ます。

 

GitLabには以下の二つのエディションが存在します。

GitLab CE : Community Edition

GitLab EE : Enterprise Edition

この中でGitLab CEがフリーでオープンソースなパッケージでMITライセンスで提供されています。

 

GitLab EEは、プロプライエタリなライセンスでGitLab CEにない機能を備えているようです。

 

GitLab CEを2分でインストール

GitLabの公式サイト

The DevSecOps Platform
From planning to production, bring teams together in one application. Ship secure code more efficiently to deliver value faster.

をブラウザで開きます。

 

image

「Download and install the open source GitLab CE in 2 minutes」

(オープンソースのGitLab CEを2分でダウンロードしてインストール)

を押します。

 

以下の画面が表示されます。

 

image

ロゴがちょっとキモいですが、気にせずに

「Select Operating System」

のところから自分の環境にあったオペレーティングシステムを選択します。

私の場合「CentOS 7」を選択しました。

 

 

GitLabではデフォルトでWebサーバーNginxがインストールされます。

 

よって、Apacheを動作させている場合は停止しておきます。

 

# systemctl stop httpd.service
# systemctl disable httpd.service

 

以下は

Download and install GitLab
Download, install and maintain your own GitLab instance with various installation packages and downloads for Linux, Kubernetes, Docker, Google Cloud and more.

からの引用ですが、日本語でコメントしておきました。

 

1. Install and configure the necessary dependencies
If you install Postfix to send email please select ‘Internet Site’ during setup. Instead of using Postfix you can also use Sendmail or configure a custom SMTP server. Do not use Exim to send email from GitLab.
On Centos 6 and 7, the commands below will also open HTTP and SSH access in the system firewall.

 

以下をコマンドから入力します。
openssh-serverのインストールと自動設定、postfixのインストールと自動設定、ファイアウォールとしてhttp(ポート80)を開けておく設定です。

 

sudo yum install openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

 

2. Download the Omnibus package and install everything

以下をコマンドから入力します。
rpmパッケージのダウンロードとインストールです。

 

curl -O https://downloads-packages.s3.amazonaws.com/centos-7.0.1406/gitlab-7.7.2_omnibus.5.4.2.ci-1.el7.x86_64.rpm
sudo rpm -i gitlab-7.7.2_omnibus.5.4.2.ci-1.el7.x86_64.rpm

 

3. Configure and start GitLab

以下をコマンドから入力します。
GitLabのコンフィギュレーションを行います。

 

sudo gitlab-ctl reconfigure

少し時間がかかります。

 

4. Browse to the hostname and login

ブラウザで開いてみて以下のユーザーでログインします。

Username: root
Password: 5iveL!fe

 

 

image

 

初回ログイン時のみパスワードの変更が要求されるのでパスワードを変更しておきます。

 

image

 

そのままログイン出来ます。 以下の画面に遷移します。

 

image

 

誇大広告ではなかったです。

本当に2分でダウンロードしてインストール出来ました!

gitlab-ctl reconfigure

というコマンドが非常に優秀なようです。

 

自動起動設定

 

GitLabはNginxを同梱していて、インストールするとデフォルトで自動起動設定になっているようです。

 

以下のファイルが関係しています。

 

/etc/systemd/system/default.target.wants/gitlab-runsvdir.service -> /opt/gitlab/embedded/cookbooks/runit/files/default/gitlab-runsvdir.service

 

中身は以下の通りです。

[Unit]
Description=GitLab Runit supervision process

[Service]
ExecStart=/opt/gitlab/embedded/bin/runsvdir-start
Restart=always

 

 

以下のコマンドのようにサービスで起動することも出来るようです。

# systemctl start gitlab-runsvdir.service

 

ただ、通常は、Linuxのサービスで起動したり停止したりせず、

gitlab-ctlコマンドを使うようです。

 

 

gitlab-ctlには以下のオプションが存在します。

cleanse
  Delete *all* gitlab data, and start from scratch.
deploy-page
  Put up the deploy page
graceful-kill
  Attempt a graceful stop, then SIGKILL the entire process group.
help
  Print this help message.
hup
  Send the services a HUP.
int
  Send the services an INT.
kill
  Send the services a KILL.
once
  Start the services if they are down. Do not restart them if they stop.
reconfigure
  Reconfigure the application.
remove_users
  Delete *all* users and groups used by gitlab
restart
  Stop the services if they are running, then start them again.
service-list
  List all the services (enabled services appear with a *.)
show-config
  Show the configuration that would be generated by reconfigure.
start
  Start services if they are down, and restart them if they stop.
status
  Show the status of all the services.
stop
  Stop the services, and do not restart them.
tail
  Watch the service logs of all enabled services.
term
  Send the services a TERM.
uninstall
  Kill all processes and uninstall the process supervisor (data will be preserved).

 

リポジトリの設定など

GitLabのデフォルトのリポジトリの場所は以下のディレクトリです。

 

/var/opt/gitlab/git-data

 

/var/opt/gitlab/git-data/gitlab-satellites

は、マージリクエストのために存在するフォルダのようです。

 

また、リポジトリは、

/var/opt/gitlab/git-data/repositories/root

のように名前空間(namespace)を持つようになっています。

 

私の環境では、すでに、ローカルの

/var/lib/git/

にすでにbareリポジトリが存在していたので、そのbareリポジトリを丸ごと以下にコピーしました。

 

/var/opt/gitlab/git-data/repositories/root

 

その後、以下のコマンドを実行してリポジトリをGitLabに取り込みます。

 

# gitlab-rake gitlab:import:repos

 

GitLabのデフォルトのリポジトリの場所は設定ファイル

/etc/gitlab/gitrab.rb

の中で、

git_data_dir

により変更することも可能です。

 

GitLabのユーザーインターフェースを見る限り、

リポジトリのフォルダ名には必ず.gitという拡張子が必要なようです。

 

Gitでbareリポジトリを作る際には、

.gitを付けるのは慣習があることは知っていましたが、

GitLabの場合、仕様上、.gitを付けることが必要なようです。

 

ユーザーの移行方法は?

GitLabはリポジトリのアクセス制御なども行うことが可能です。

 

そのために、GitLabにユーザーの登録画面が存在します。

 

これまで、Linuxの/homeにあるユーザーとgitグループでリポジトリを使っていたので、一括でGitLabにユーザーを登録する方法が見つからないのでちょっと困っています。

 

2015.02.20 追記

その後、Stack Overflowで質問したらアドバイスがありました。

以下の記事にまとめています。

 

GitLabのpython-gitlabでコマンドラインでユーザーを一括で追加、アカウント登録、削除する方法
GitLabのセットアップについて、以下の記事の通り完了しました。 その後、GitLabでGUI画面から1人1人ユーザー登録するのはGUIから行えます。 一方で、コマンドラインから一括でバルクでユーザーを登録する方法を調...

 

まとめ

以下の記事の通り、Ginatraを使ってみてイマイチだったので、GitLabはいい感じだと思っています。

 

GitWebが日本語でエラー出すので、Ginatra(ギナトラ)のインストール手順をまとめた
GitWebが日本語でエラー出すので、Ginatraをインストールしてみました。 Ginatraのインストール手順をまとめました。 GitWebで日本語のhistoryをクリックするとThis page contains the ...

 

GitLabは単なるGitのWebインターフェースに留まらず、リポジトリのアクセス権限やユーザー登録も備えたGitの管理システムと言えるでしょう。

 

Gitについてのおすすめの本

 

↓Gitについてのおすすめの本はコチラ

Git

 

 

コメント

  1. […] CentOS 7にGitHubライクなオンプレミス GitLab CE (community edition) を2分でインスト… […]

  2. […] CentOS 7にGitHubライクなオンプレミス GitLab CE (community edition) を2分でインスト… […]

タイトルとURLをコピーしました