LoginSignup
14
15

More than 5 years have passed since last update.

GitLab on AWS(Ubuntu)

Last updated at Posted at 2013-01-09

参考URL
https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md

1. Packages / Dependencies

システムのアップデート

sudo apt-get update
sudo apt-get upgrade

vimをインストール

sudo apt-get install -y vim

必要なパッケージをインストール

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

Pythonをインストール

sudo apt-get install python

バージョンが2.5+であることを確認 (3.xはまだサポート外)

python --version

2. Ruby

Rubyをダウンロード&コンパイル

mkdir /tmp/ruby && cd /tmp/ruby
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar xfvz ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327
./configure
make
sudo make install

Bundler Gemをインストール

sudo gem install bundler

3. System Users

Git and Gitoliteユーザーを作成:

sudo adduser \
--system \
--shell /bin/sh \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git

GitLabユーザーを作成:

sudo adduser --disabled-login --gecos 'GitLab' gitlab

グループの追加

sudo usermod -a -G git gitlab

SSHキーの生成

sudo -u gitlab -H ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa

4. Gitolite

Gitoliteソースコードをクローンする:

cd /home/git
sudo -u git -H git clone -b gl-v320 https://github.com/gitlabhq/gitolite.git /home/git/gitolite

Gitoliteスクリプトを環境変数に設定

sudo -u git -H mkdir /home/git/bin
sudo -u git -H sh -c 'printf "%b\n%b\n" "PATH=\$PATH:/home/git/bin" "export PATH" >> /home/git/.profile'
sudo -u git -H sh -c 'gitolite/install -ln /home/git/bin'

gitlabユーザーのSSHキーをコピーする

sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
sudo chmod 0444 /home/git/gitlab.pub

上記のキーを管理者キーとして使用するように設定

sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"

Gitoliteをgitで管理できるように設定

sudo chmod 750 /home/git/.gitolite/
sudo chown -R git:git /home/git/.gitolite/

レポジトリのディレクトリを設定

sudo chmod -R ug+rwXs,o-rwx /home/git/repositories/
sudo chown -R git:git /home/git/repositories/

StrictHostKeyCheckingを無効にする

echo "Host localhost
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null" | sudo tee -a /etc/ssh/ssh_config

設定テスト

sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin

テストしてOKだったらクローンしたものを削除

sudo rm -rf /tmp/gitolite-admin

5. Database

MySQL
MySQL関連のパッケージをインストール

sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

MySQLにログイン

$ mysql -u root -p

GitLabユーザーを作成

mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '{$password}';

GitLabデータベースを作成

mysql> CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

GitLabユーザーの権限設定

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON gitlabhq_production.* TO 'gitlab'@'localhost';

データベース切断

mysql> \q

上記で設定したユーザーでログインできるか確認

sudo -u gitlab -H mysql -u gitlab -p -D gitlabhq_production

6. GitLab

GitLabをインストール

cd /home/gitlab

GitLabレポジトリをクローンする

sudo -u gitlab -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab

gitlabディレクトリに移動する

cd /home/gitlab/gitlab

安定版にチェックアウトする

sudo -u gitlab -H git checkout 4-0-stable

設定
gitlabディレクトリに移動する

cd /home/gitlab/gitlab

設定ファイルのサンプルをコピーする

sudo -u gitlab -H cp config/gitlab.yml.example config/gitlab.yml

Make sure to change "localhost" to the fully-qualified domain name of your
host serving GitLab where necessary

sudo -u gitlab -H vim config/gitlab.yml

Make sure GitLab can write to the log/ and tmp/ directories

sudo chown -R gitlab log/
sudo chown -R gitlab tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/

Copy the example Unicorn config

sudo -u gitlab -H cp config/unicorn.rb.example config/unicorn.rb

Configure GitLab DB settings
Mysql

sudo -u gitlab cp config/database.yml.mysql config/database.yml

Make sure to update username/password in config/database.yml.
Install Gems

cd /home/gitlab/gitlab

sudo gem install charlock_holmes --version '0.6.9'

For mysql db

sudo -u gitlab -H bundle install --deployment --without development test postgres

Configure Git

sudo -u gitlab -H git config --global user.name "GitLab"
sudo -u gitlab -H git config --global user.email "gitlab@ec2----.ap-southeast-1.compute.amazonaws.com"

Setup GitLab Hooks

sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
sudo chown git:git /home/git/.gitolite/hooks/common/post-receive

Initialise Database and Activate Advanced Features

sudo -u gitlab -H bundle exec rake gitlab:app:setup RAILS_ENV=production

Check Application Status

sudo -u gitlab -H bundle exec rake gitlab:env:info RAILS_ENV=production
sudo -u gitlab -H bundle exec rake gitlab:check RAILS_ENV=production

Install Init Script
Download the init script (will be /etc/init.d/gitlab):

sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab -P /etc/init.d/
sudo chmod +x /etc/init.d/gitlab

Make GitLab start on boot:

sudo update-rc.d gitlab defaults 21

Start your GitLab instance:

sudo service gitlab start
or
sudo /etc/init.d/gitlab restart

7. Nginx

Installation

sudo apt-get install nginx

Site Configuration

sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

Change YOUR_SERVER_IP and YOUR_SERVER_FQDN
to the IP address and fully-qualified domain name
of your host serving GitLab

sudo vim /etc/nginx/sites-enabled/gitlab

sudo rm /etc/nginx/sites-enabled/default

Restart

sudo /etc/init.d/nginx restart

完了!

Visit YOUR_SERVER for your first GitLab login. The setup has created an admin account for you. You can use it to log in:

[重要]

port:60010をあけておく

14
15
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
14
15