
先日、とにかく安くということで、serversman@vpsにgitlabをインストールしてみたものの、重すぎたため(当たり前か・・)。さくらのVPS
と迷ったのだけど、最近、VPSのベンチマークで評判が良いお名前.com VPS
で再設定することにした。GitLabのインストールは結構戸惑うので、例により自分のためにメモ。OS再インストールから何度か試してみたので、ほぼコピペでいけるはず。所要時間は1時間かからないはず。
また試したみた感想としては、評判通り早く、体感にも全然違う (ServersManと比べてだけど)。2〜3人の開発チームでの使用を考えているのでこの程度で十分かなと思います。しばらくGitlab on お名前.com@VPSで試してみたいと思います。
今回設定する内容
- VPS: お名前.com VPS(KVM)
1GBプラン (月額840円/年間契約)
- OS: CentOS 6.2
- MySQL 5.6.14 (最新版)
- Ruby 1.9.3
- Git 1.8.5.2 (最新版)
- Gitlab 6.4 (最新版)
- RVM 1.25.14 (最新版)
※ “最新版”は2014年1月11日時点でとなります。
目次
Gitlabの手順が多すぎでした。
- 必要なライブラリインストール
- MySQL5.6.14インストール
- Ruby1.9.3インストール
- Gitlab6.4インストール
- a. Git1.8.5.2をインストール
- b. Redisインストール
- c. Gitユーザー作成
- d. Gitlab-shellをインストール
- e. MYSQLデータベース作成
- f. Gitlabインストール
- g. Gitlabデータベース設定
- h. 必要なGemパッケージインストール
- i. データベース初期化&セットアップ
- j. Init Script設定 & GitLab起動
- k. Passengerのインストール&Proxy設定
- l. チェック
- m. プラウザで動作確認
1.サーバー初期設定
SSH接続方法についてはお名前.comの設定完了メールをご確認ください。
最低限必要なライブラリを予めインストールしておく。sourceディレクトリを作成してそこで作業する。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
(SSH接続) // wgetをインストール $ yum install -y wget // vimをインストール $ yum install -y vim // epelパッケージをインストール $ mkdir ~/sources $ cd ~/sources $ wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm $ rpm -ivh epel-release-6-8.noarch.rpm // 必要なライブラリを一括インストール $ yum install -y --enablerepo=epel make gcc gcc-c++ curl curl-devel gcc gcc-c++ git openssl-devel httpd-devel readline-devel zlib-devel libffi-devel install libyaml-devel |
2.MySQL5.6.14インストール
MySQLはRPMパッケージから最新版をインスートルする。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
$ yum -y localinstall http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.14-1.el6.x86_64.rpm $ yum -y localinstall http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-shared-5.6.14-1.el6.x86_64.rpm \ http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-server-5.6.14-1.el6.x86_64.rpm \ http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-devel-5.6.14-1.el6.x86_64.rpm \ http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.14-1.el6.x86_64.rpm $ chkconfig mysql on $ vim /etc/my.cnf (以下の内容を記述) [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql symbolic-links=0 character-set-server=utf8 innodb_file_per_table query-cache-size=16M [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [mysql] default-character-set=utf8 // MySQL起動。MySQLルートユーザーのパスワード設定 $ /etc/init.d/mysql start Starting MySQL... SUCCESS! // MySQLパスワード設定 (5.6からデフォルトでパスワードなしでログイン不可になった) $ cat /root/.mysql_secret The random password set for the root user at Fri Dec 27 07:08:23 2013 (local time): {初期パスワード} $ mysql -u root -p (パスワードを聞かれるので初期パスワードを入力) > SET PASSWORD FOR root@localhost=PASSWORD(''); // パスワードを空する場合 > exit |
3. Ruby1.9.3インストール
RubyはRVMを用いてインストール。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// RVMをインストール $ curl -sSL https://get.rvm.io | bash -s stable $ echo "source /etc/profile.d/rvm.sh" >> ~/.bash_profile $ source ~/.bash_profile // ruby1.9.3をインストール $ rvm list known (インストール可能にRuby一覧を確認) $ rvm install 1.9.3 $ rvm gemset create rails3 $ rvm use --default 1.9.3@rails3 // 必要になるGEMパッケージを予めインストール $ gem install --no-rdoc --no-ri activesupport therubyracer |
4. GitLab6.4インストール
gitlabのインストールを行います。gitlabのインストール&設定はgitlabユーザーで行います。
a. Git1.8.5.2をインストール
Gitの最新版を入れておく。(2014/1/13時点で1.8.5.2)
1 2 3 4 5 6 7 8 9 10 |
$ cd ~/sources $ yum -y install perl-ExtUtils-MakeMaker $ yum -y install tcl*.x86_64 $ yum install -y gettext-devel gettext-libs $ wget https://git-core.googlecode.com/files/git-1.8.5.2.tar.gz $ tar zxvf git-1.8.5.2.tar.gz $ cd git-1.8.5.2 $ ./configure $ make $ make install |
b. Redisインストール
1 2 3 4 5 6 7 8 |
$ yum install -y --enablerepo=epel redis $ /etc/init.d/redis start $ chkconfig redis on $ yum install -y libxml2-devel libxslt-devel $ yum --enablerepo=epel -y install libicu-devel libxml2 libxml2-devel $ gem install charlock_holmes --version '0.6.9' --no-rdoc --no-ri $ gem install --no-ri --no-rdoc bundler |
c. Gitユーザー作成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ useradd -c 'GitLab' -s /bin/bash git $ chmod 755 /home/git $ passwd git (任意のパスワード設定) $ su - git gitlab$ cd /home/git gitlab$ mkdir .ssh gitlab$ touch .ssh/authorized_keys gitlab$ chmod 600 .ssh/authorized_keys gitlab$ chmod 700 .ssh gitlab$ git config --global user.name "GitLab" gitlab$ git config --global user.email "gitlab@localhost" gitlab$ exit (rootユーザーに戻る) |
d. Gitlab-shellをインストール
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Go to home directory $ cd /home/git // Clone gitlab shell sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git -b v1.8.0 $ cd gitlab-shell $ sudo -u git -H cp config.yml.example config.yml // gitlab_urlを変更する。 $ vim config.yml - gitlab_url: "http://localhost/" + gitlab_url: "http://yourdomain.com/" // RVMのパスを通してインストール実行 $ sudo -u git -H /usr/local/rvm/bin/rvm env --path ruby-1.9.3@rails3 & ./bin/install |
e. MYSQLデータベース作成
1 2 3 |
$ mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci" (パスワードを聞かれるので、先ほど設定したMySQLのパスワードを入力) $ mysql -u root -p -e 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON gitlabhq_production.* TO "gitlab"@"localhost" identified by "gitpass"' |
f. Gitlabインストール
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
$ cd /home/git/ $ sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git -b 6-4-stable gitlab // gitlabディレクトリへ移動 $ cd /home/git/gitlab // gitlab.ymlコピー&修正 $ sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml $ sudo -u git -H vim config/gitlab.yml - host: localhost + host: yourdomain.com - bin_path: /usr/bin/git + bin_path: /usr/local/bin/git // 先ほど入れた1.8.5 // Make sure GitLab can write to the log/ and tmp/ directories $ sudo chown -R git log/ $ sudo chown -R git tmp/ $ sudo chmod -R u+rwX log/ $ sudo chmod -R u+rwX tmp/ // Create directory for satellites $ sudo -u git -H mkdir /home/git/gitlab-satellites // Create directories for sockets/pids and make sure GitLab can write to them $ sudo -u git -H mkdir tmp/pids/ $ sudo -u git -H mkdir tmp/sockets/ $ sudo chmod -R u+rwX tmp/pids/ $ sudo chmod -R u+rwX tmp/sockets/ // Create public/uploads directory otherwise backup will fail $ sudo -u git -H mkdir public/uploads $ sudo chmod -R u+rwX public/uploads // Copy the example Unicorn config $ sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb // Uniconの設定をサーバースペックに応じて変更。(タイムアウトを増やしておく) // Ex. change amount of workers to 3 for 2GB RAM server $ sudo -u git -H vim config/unicorn.rb - timeout 30 + timeout 300 // Rack attack config $ sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb // Configure Git global settings for git user, useful when editing via web // Edit user.email according to what is set in gitlab.yml $ sudo -u git -H git config --global user.name "GitLab" $ sudo -u git -H git config --global user.email "gitlab@localhost" $ sudo -u git -H git config --global core.autocrlf input |
g. Gitlabデータベース設定
1 2 3 4 5 6 7 8 9 10 11 |
// Mysql $ sudo -u git cp config/database.yml.mysql config/database.yml $ sudo -u git -H vim config/database.yml (productionのusername/password/hostを変更する) + username: gitlab + password: "gitpass" + host: localhost $ Make config/database.yml readable to git only sudo -u git -H chmod o-rwx config/database.yml |
h. 必要なGemパッケージインストール
Gitlabに必要なgemパッケージをインストールします。
1 2 |
$ cd /home/git/gitlab $ sudo -u git -H /usr/local/rvm/bin/rvm env --path ruby-1.9.3@rails3 & bundle install --deployment --without development test postgres aws |
i. データベース初期化&セットアップ
1 2 3 4 5 6 7 |
$ sudo -u git -H /usr/local/rvm/bin/rvm env --path ruby-1.9.3@rails3 & bundle exec rake gitlab:setup RAILS_ENV=production (データベース作成するか聞かれるので"yes"を入力) (最後にログインアカウントを教えてくれる) login.........admin@local.host password......5iveL!fe |
j. Init Script設定 & GitLab起動
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab $ sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab $ sudo chkconfig --add gitlab $ sudo chkconfig gitlab on $ sudo /etc/init.d/gitlab restart // ログローテートを設定 $ sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab // reposotoriesのユーザー:グループをgitにする。 $ sudo chown -R git:git /home/git/repositories/ $ sudo chown -R git:git /home/git/gitlab/log/application.log // $ sudo chown -R git:git /home/git/ |
k. Passengerのインストール&Proxy設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
// Passengerのインストール $ cd ~/sources $ gem install passenger --no-rdoc --no-ri $ passenger-install-apache2-module $ vim /etc/httpd/conf.d/passenger.conf (下記入力) LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p484@rails3/gems/passenger-4.0.33/buildout/apache2/mod_passenger.so PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p484@rails3/gems/passenger-4.0.33 PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-1.9.3-p484@rails3/ruby // サーバーネーム設定 $ echo "ServerName {あなたのドメイン名}" >> /etc/httpd/conf/httpd.conf // バーチャルホストを有効にする。 $ echo "NameVirtualHost *:80" >> /etc/httpd/conf/httpd.conf // Gitlabの設定 $ vim /etc/httpd/conf.d/gitlab.conf <VirtualHost *:80> ServerName yourdomain.com DocumentRoot /home/git/gitlab/public ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ </VirtualHost> // Apacheサーバー再起動 $ /etc/init.d/httpd restart // Apache自動起動 $ chkconfig httpd on |
l. チェック
GitLabに必要な動作環境が整ったか確認することができます。まずは基本情報を表示。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
$ sudo -u git -H /usr/local/rvm/bin/rvm env --path ruby-1.9.3@rails3 & bundle exec rake gitlab:env:info RAILS_ENV=production System information System: CentOS release 6.2 (Final) Current User: root Using RVM: yes RVM Version: 1.25.14 Ruby Version: 1.9.3p484 Gem Version: 2.2.1 Bundler Version:1.5.2 Rake Version: 10.1.0 GitLab information Version: 6.4.3 Revision: 38397db Directory: /home/git/gitlab DB Adapter: mysql2 URL: http://yourdomain.com HTTP Clone URL: http://yourdomain.com/some-project.git SSH Clone URL: git@yourdomain.com:some-project.git Using LDAP: no Using Omniauth: no GitLab Shell Version: 1.8.0 Repositories: /home/git/repositories/ Hooks: /home/git/gitlab-shell/hooks/ Git: /usr/local/bin/git |
続いてGitLabの設定チェック。これでエラーがなければ問題なく動作するはず。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
$ sudo -u git -H /usr/local/rvm/bin/rvm env --path ruby-1.9.3@rails3 & bundle exec rake gitlab:check RAILS_ENV=production Checking Environment ... Git configured for git user? ... yes Has python2? ... yes python2 is supported version? ... yes Checking Environment ... Finished Checking GitLab Shell ... GitLab Shell version >= 1.7.9 ? ... OK (1.8.0) Repo base directory exists? ... yes Repo base directory is a symlink? ... no Repo base owned by git:git? ... yes Repo base access is drwxrws---? ... yes update hook up-to-date? ... yes update hooks in repos are links: ... can't check, you have no projects Running /home/git/gitlab-shell/bin/check Check GitLab API access: OK Check directories and files: /home/git/repositories: OK /home/git/.ssh/authorized_keys: OK Test redis-cli executable: redis-cli 2.4.10 Send ping to redis server: PONG gitlab-shell self-check successful Checking GitLab Shell ... Finished Checking Sidekiq ... Running? ... yes Number of Sidekiq processes ... 1 Checking Sidekiq ... Finished Checking LDAP ... LDAP is disabled in config/gitlab.yml Checking LDAP ... Finished Checking GitLab ... Database config exists? ... yes Database is SQLite ... no All migrations up? ... yes GitLab config exists? ... yes GitLab config outdated? ... no Log directory writable? ... yes Tmp directory writable? ... yes Init script exists? ... yes Init script up-to-date? ... yes projects have namespace: ... can't check, you have no projects Projects have satellites? ... can't check, you have no projects Redis version >= 2.0.0? ... yes Your git bin path is "/usr/local/bin/git" Git version >= 1.7.10 ? ... yes (1.8.5) Checking GitLab ... Finished |
m. ブラウザでアクセスしてみる。
iptablesでブロックかかっているので一旦停止。(todo:正しく設定する)。また初回起動時は時間が掛かるので気長に待つ。また最初は”Proxy Error”となる場合があるので、その場合は再読みしてみると表示されるようになる。
1 |
$ /etc/init.d/iptables stop |
下記の画面が表示されれば完了。
お疲れ様でした。
エラー対応
その1. ブラウザ上でUniconサーバーを確認できない。
お名前.comのVPSではポート制限が掛かっているので、ApacheのProxy設定で80ポート経由で閲覧する。開放ポートについては下記確認。
>> http://help.onamae.com/app/answers/detail/a_id/9191
その2. sudo bundle時にrvmのパスが通らない。
sudoの時にrvmのパスが通っていないため起こる。
1 2 |
Starting unicorn: bash: bundle: コマンドが見つかりません [失敗] Starting sidekiq: bash: bundle: コマンドが見つかりません [失敗] |
解決方法: 下記のように実行時にrvmの環境を読み込んで対応。(rvmsudoでもいいかも)
1 |
$ sudo -u git -H /usr/local/rvm/bin/rvm env --path ruby-1.9.3@rails3 & {Bundleコマンド} |
その3. Unicon Timeout エラー
エラー: Gitlabは初回起動時に時間が掛かるが、Unicornのタイムアウトはデフォルトでは30秒のため、タイムアウトエラーが起きる。解決方法として、gitlab/config/unicorn.rbのtimeout設定を多め(300s)に増やしておく。
1 2 3 |
E, [2014-01-14T11:20:42.064930 #14251] ERROR -- : worker=0 PID:14281 timeout (31s > 30s), killing E, [2014-01-14T11:20:42.098352 #14251] ERROR -- : reaped #<Process::Status: pid 14281 SIGKILL (signal 9)> worker=0 I, [2014-01-14T11:20:42.114485 #14318] INFO -- : worker=0 ready |
>> http://radiumblue.net/blog/2013/01/18/unicorn-error-gitlab-configuration/
その4. Git Clone時にエラー”fatal: The remote end hung up unexpectedly”
エラー内容: 容量大きめのGitレポジトリをCloneしたところ発生。
1 2 3 4 5 6 |
$ git clone http://gitlab.****.***/username/*****.git Cloning into '********'... remote: Counting objects: 6994, done. remote: Compressing objects: 100% (4956/4956), done. Receiving objects: 25% (1756/6994), 27.34 MiB | 185.00 KiB/s fatal: The remote end hung up unexpectedly MiB | 230.00 KiB/s |
Gitlabサーバーのログを見たところ、下記のようなエラーが! タイムアウト扱いになるんだ。
1 2 |
E, [2014-01-19T16:43:43.570393 #30209] ERROR -- : worker=1 PID:27148 timeout (301s > 300s), killing error: git-upload-pack died of signal 13 |
解決方法: Unicornの設定(gitlab/config/unicorn.rb)でTimeoutをさらに増やしたところ、解決した。
1 2 3 4 |
$ vim /home/git/gitlab/config/unicorn.rb - timeout 300 + timeout 3000 $ /etc/init.d/gitlab restart |
参考