GitLabの手動インストールと基本操作ガイド

GitLabは、Gitをベースにしたオープンソースのリポジトリ管理プラットフォームであり、Webインターフェースを通じてコードの管理・共同開発を支援します。以下では、Ubuntu環境における手動インストール手順と初期設定を解説します。

パッケージソースの設定

国内ミラーを使用して高速化:

# /etc/apt/sources.list を編集
deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ precise-security main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ precise-updates main universe restricted multiverse

# 更新
apt-get update

依存ライブラリのインストール

sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev \
libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server \
redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev \
libicu-dev logrotate python-docutils git git-core gitweb postfix

GitとRubyの環境整備

Gitバージョンが古い場合はアップグレード推奨(オプション):

cd /tmp
curl -L https://github.com/git/git/archive/v2.30.0.tar.gz | tar xz
cd git-2.30.0
make prefix=/usr/local all
sudo make prefix=/usr/local install

Ruby 2.0+ のコンパイルインストール:

cd /tmp
wget https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.gz
tar xzf ruby-2.7.2.tar.gz
cd ruby-2.7.2
./configure --disable-install-rdoc
make && sudo make install

Gemソースを中国鏡像に切り替え(速度改善用):

gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
sudo gem install bundler --no-document

専用ユーザーの作成

sudo adduser --disabled-login --gecos 'GitLab Service User' git

GitLab Shellの導入

cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git
cd gitlab-shell
sudo -u git -H cp config.yml.example config.yml
sudo -u git -H sed -i 's|localhost|gitlab.yourdomain.local|g' config.yml
sudo -u git -H ./bin/install

データベースの準備(MySQL)

sudo apt-get install -y mysql-server libmysqlclient-dev
sudo mysql -u root -p
> CREATE DATABASE gitlab_prod;
> GRANT ALL PRIVILEGES ON gitlab_prod.* TO 'gitlab_user'@'localhost' IDENTIFIED BY 'secure_password';
> FLUSH PRIVILEGES;

GitLab本体のセットアップ

cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-foss.git gitlab
cd gitlab
sudo -u git -H git checkout v13.12.15 # 安定版タグ指定

設定ファイルの調整:

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u git -H vim config/gitlab.yml
# host: gitlab.yourdomain.local
# email_from: notify@yourdomain.local
# signup_enabled: true

ディレクトリと権限の設定:

sudo -u git -H mkdir -p tmp/{pids,sockets} public/uploads repositories gitlab-satellites
sudo chown -R git:git log/ tmp/ public/uploads
sudo chmod -R u+rwX log/ tmp/ public/uploads

Unicornサーバー設定(ポート8081):

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H sed -i 's|listen "127.0.0.1:8080"|listen "gitlab.yourdomain.local:8081"|' config/unicorn.rb

データベース接続設定:

sudo -u git -H cp config/database.yml.mysql config/database.yml
sudo -u git -H vim config/database.yml
# production:
#   adapter: mysql2
#   database: gitlab_prod
#   username: gitlab_user
#   password: "secure_password"
#   host: localhost

メール送信設定(SMTP):

sudo -u git -H vim config/environments/production.rb
# config.action_mailer.delivery_method = :smtp
# config.action_mailer.smtp_settings = {
#   address: "smtp.gmail.com",
#   port: 587,
#   domain: "yourdomain.local",
#   user_name: "notify@yourdomain.local",
#   password: "app_password",
#   authentication: "plain",
#   enable_starttls_auto: true
# }

依存GemのインストールとDB初期化

sudo -u git -H bundle config mirror.https://rubygems.org https://gems.ruby-china.com
sudo -u git -H bundle install --deployment --without development test postgres aws

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# 「yes」で初期化 → 管理者アカウント admin@local.host / パスワードが表示される

サービス登録と起動

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo update-rc.d gitlab defaults 21
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
sudo service gitlab start

Webサーバー(Nginx)の設定

sudo apt-get install nginx
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -sf /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/
sudo vim /etc/nginx/sites-available/gitlab
# server_name gitlab.yourdomain.local;
# proxy_pass http://gitlab.yourdomain.local:8081;

sudo systemctl restart nginx

初回ログインと基本操作

ブラウザで http://gitlab.yourdomain.local にアクセスし、初期管理者アカウントでログイン。

  • 初回ログイン時にパスワード変更を要求される
  • ユーザー情報(メールアドレス)を更新すると確認メールが送信される
  • 「DevTeam」というグループを作成
  • そのグループ配下に「SampleProject」リポジトリを作成
  • SSH公開鍵をユーザー設定に登録
  • 新規ユーザー「devuser」を登録し、DevTeamグループにReporter権限で追加
  • devuserでログイン → SampleProjectが閲覧可能だが、masterブランチへのpushは拒否される

タグ: GitLab Ubuntu nginx MySQL Ruby

6月3日 22:07 投稿