AWSにgitlab5.3をインストールまでの備忘録です。
めっちゃ長いです。あしからず。
この手順書ではシステム全体に入っているruby1.8には手をつけず、
gitユーザー環境のみにruby2.0を入れていますが、修正作業が増えるので
問題がない場合はシステム全体のruby1.8をruby2.0にしてしまう方がトラブルにあわないかも知れません。
AWS EC2とS3を利用します。
OSはAmazon Linuxを使います。
途中まで手順書を書いていたのですが、MacVimがクラッシュしてしまったので、
最初のあたりはうろ覚えです。
このメモはSublimeで書いてます。
やはりvimはメモ帳には不向きですね。
AWSを利用するのは初めてなので、そのあたりも解説します。
safariを使った場合、鍵ペアを作る際に、同時に秘密鍵(ec2key.pem)がダウンロードされますが、
このファイルは~/.ec2/というフォルダを作ってそこに置いておくとこにします。
ファイル権限は400にしておきます。
sshでログインする場合はAWS管理画面でインスタンスからActions-Connectを実行し、
Connect with a standalone SSH Clientを実行し、
表示される「ssh -i ec2key.pem ec2-user@xx.xx.xx.xx」を~/.ec2/に移動してから実行します。
また、ルートユーザーになるには、「sudo su -」を実行すればよいです。
elastic IPを作成し、立ち上げたOSインスタンスに割り当てます。
またセキュリティポリシーにhttpのinboundアクセスを追加しておきます。
$ifconfig -a
を実行してプライベートアドレスをメモしておきます。
172.31.x.x
/etc/hostsに
172.31.x.x gitlab.com
を追加しておきます。ホスト名はプライベートなので適当です。
Elastic IPではNATによって外部IPとプライベートIPが変換されます。
設定ファイル群にはプライベートホスト名(gitlab.com)とプライベートIP(172.31.x.x)を使用します。
$sudo yum update -y
$sudo yum upgrade -y
sudo yum install -y git
gitはversion 1.8.1.4がインストールされました。
sudo yum install -y \ gcc-c++ \ git-core \ libffi-devel \ libicu-devel \ libxml2-devel \ libxslt-devel libyaml-devel \ make \ mysql \ mysql-devel \ patch \ perl-Time-HiRes \ postfix \ readline-devel \ zlib-devel
$ sudo adduser git
# chmod 755 /home/git
gitユーザーの環境にのみruby2.0をインストールします。
rbenvを使います。
手順は省略。私の別のエントリー参照。
$ gem install bundler
$ gem install charlock_holmes --version '0.6.9.4'
gitユーザーのgitコンフィグ設定
$ git config --global user.name "Gitlab"
$ git config --global user.email "gitlab@localhost"
$ git config --global core.autocrlf input
redisのインストール
残念ながらAmazon Linuxのyumコマンドではredisがインストールできないので、手動で入れます。
# cd /tmp
# wget http://redis.googlecode.com/files/redis-2.6.12.tar.gz
# tar zxvf redis-2.6.12.tar.gz
# cd /redis2.6.12
# make
# make install
# mkdir /etc/redis
# cp utils/redis_init.script /etc/init.d/redis
# cp redis.conf /etc/redis/6379.conf
# mkdir /usr/local/redis
コピーした6379.confファイルを編集する。
上から下に変更する。
daemonize no
daemonize yes
pidfile /var/run/redis.pid
pidfile /var/run/redis_6379.pid
logfile stdout
logfile /var/log/redis.log
dir ./
dir /usr/local/redis
/etc/init.d/redisファイルの2行目に以下を追加する。
# chkconfig: - 85 15
# description: redis-server
# processname: redis
# chkconfig --add redis
# chkconfig redis on
# service redis start
gitlab-shellのインストール
$ git clone https://github.com/gitlabhq/gitlab-shell.git
$ cd gitlab-shell
$ git checkout v1.7.0
$ cp config.yml.example config.yml
$ vi config.yml
gitlab_url:の部分を変更しますが、
elasticIPのprivateホスト名(gitlab.com)を入れます。
$ ./bin/install
MySQLのインストール
# yum install -y mysql-server
# chkconfig mysqld on
# service mysqld start
# /usr/bin/mysql_secure_installation
Enter current password for root (enter for none):
そのままEnter
Set root password? [Y/n]
Yを入力してパスワードを設定します。
Remove anonymous users? [Y/n]
Yを入力します。
Disallow root login remotely? [Y/n]
Yを入力します。
Remove test database and access to it? [Y/n]
Yを入力します。
Reload privilege tables now? [Y/n]
Yを入力します。
# service mysqld restart
# mysql -u root -p
mysql> create user 'gitlab'@'localhost' identified by 'XXXXX';
mysql> create database if not exists `gitlabhq_production` default character
set `utf8` collate `utf8_unicode_ci`;
mysql> grant select, lock tables, insert, update, delete, create, drop, index, alter on `gitlabhq_production`.* to 'gitlab'@'localhost';
mysql> exit
ログインできることを確認します。
$ mysql -u gitlab -p -D gitlabhq_production
gitlabをインストールします。
$ cd ~
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
$ cd ~/gitlab
$ git checkout 5-3-stable
$ cp config/gitlab.yml.example config/gitlab.yml
$ vi config/gitlab.yml
host:の部分を変更します。
$ mkdir tmp/pids
$ mkdir tmp/sockets
$ mkdir public/uploads
$ mkdir gitlab-satellites
$ cp config/unicorn.rb.example config/unicorn.rb
GitLab DB settingsを行います。
$ cp config/database.yml.mysql config/database.yml
$ vi config/database.yml
production:のpassword:の部分を変更します。
bundle install に--pathをつけているところがミソです。
間違いなくgitユーザ環境にgemをインストールさせます。
でないと、なぜかシステム全体(ruby1.8)のgemを見にいってgemが見つかりませんぜってエラーがでる。
理屈は分からん。
$ chmod o-rwx config/database.yml
$ cp config/puma.rb.example config/puma.rb
$ bundle install --path --deployment --without development test postgres unicorn aws
$ bundle exec rake gitlab:setup RAILS_ENV=production
$ bundle exec rake sidekiq:start RAILS_ENV=production
$ bundle exec rake gitlab:check RAILS_ENV=production
$ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
$ sudo chmod +x /etc/init.d/gitlab
$ sudo chkconfig --add gitlab
$ sudo chkconfig gitlab on
gitユーザーのrubyのバージョンのみをあげている関係上、gitlabファイルの中身を編集します。
一つは43行目あたりの
sudo -i -u $APP_USER ...
に変更します。これやらないとruby1.8のままになってしまい、動きません。次に、
RAILS_ENV=production bundle exec
を実行している部分
すべての前に
cd $APP_ROOT &&
を追加します。
$ sudo service gitlab start
Nginxのセットアップ
#yum install -y nginx
iptablesが有効になっているため、とりあえず停止しておく。
# chkconfig iptables off
# service iptables stop
/home/git/gitlab/lib/support/nginx/gitlab
上記のファイルを/etc/nginx/conf.d/gitlab.confファイルとしてコピーし、
オーナー、権限を調整します。
ファイルの中身は
YOUR_SERVER_IDとYOUR_SERVER_FQDNの部分を書き換えます。
# service nginx restart
ブラウザでhttp://外部DNS名にアクセスし
admin@local.host
5iveL!fe
でログインできたら完了です。
最後にgitユーザーのログインシェルを/sbin/nologin
に変更しrootからもログインできないようにしておきます。