GitlabをUbuntu11.10 Serverに導入
Githubのような環境をクローズドな環境に構築できるOSS Gitlabを試してみました。
Gitのリポジトリを集中的に管理するのには非常に便利だと思います。
今までviewgitとかでGitリポジトリをWebで見せれるようにしたりしていましたが、
全然UIもいいし、CommentやIssue機能など使い方次第でかなり便利に活用できそうです。
以下、インストールした際のログを残しておきます。
あまりまだ情報が少ないので、結構苦戦しました。
今回は、Ubuntu Server 11.10 64bitにインストールしていきました。
https://github.com/gitlabhq/gitlabhq
ここのREADMEを参考にインストール
rubyインストール
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz $ tar xvzf ruby-1.9.2-p290.tar.gz $ cd ruby-1.9.2-p290 $ ./configure --prefix=/usr/local/ruby $ make $ sudo make install $ export PATH=/usr/local/ruby/bin:$PATH
rubygemsインストール
$ wget http://rubyforge.org/frs/download.php/74619/rubygems-1.7.2.tgz $ tar xvzf rubygems-1.7.2.tgz $ cd rubygems-1.7.2 $ sudo ruby setup.rb
git インストール
$ sudo aptitude install git
zlibインストール
$ sudo aptitude install zlib1g-dev $ cd /var/install/ruby-1.9.2-p290/ext/zlib $ ruby extconf.rb $ make $ sudo make install
easy_installインストール
$ cd /var/install $ wget http://peak.telecommunity.com/dist/ez_setup.py $ sudo python ez_setup.py
その他必要なものをインストール
$ sudo aptitude install libxml2-dev libxslt-dev libsqlite3-dev libcurl4-openssl-dev libreadline5-dev libc6-dev libssl-dev libmysql++-dev make build-essential
gitosisインストール
gitosisはGitlabのバックエンドでgitリポジトリの管理やgitリポジトリへのアクセス用の鍵管理を実施します。
$ sudo aptitude install gitosis
gitユーザ追加
管理するgitリポジトリにアクセスするためのユーザ
$ sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git
キーペア作成
ここで登録した鍵を使うことでGitlabに登録したgitリポジトリからcloneしたり、pushしたりできるようになります。
$ ssh-keygen -t rsa ここで作成する鍵を用いてgit cloneしたりpushしたりできるようになります。
キーの登録およびgitosis-admin.gitの初期化
$ sudo -H -u git gitosis-init < ~/.ssh/id_rsa.pub Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/ $ sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
gitosis-initを実行すると、/home/git/repositories/gitosis-admin.gitが作られ、その中にキーが追加登録されます。
最後にhookスクリプトに実行権限を付与します。
このhookスクリプトが正しく動作しないと、GitLabから鍵を追加した際に、/home/git/.ssh/authorized_keysが更新されなくなります。
GitLabインストール
ここまで準備して、GitLabをインストールしていきます。
GitLabのインストール時にもいろいろはまったのでその過程を記録しておきます。
まずはGitLabのソースコードをGithubからcloneしてきます。
$ mkdir /var/git $ cd /var/git $ git clone git://github.com/gitlabhq/gitlabhq.git
pythonのsyntaxhighlight用ライブラリのpygmentsのインストール、sudoersにgitユーザがNOPASSWRDでrmを実行できるよう設定、bundlerのインストールと進めていきます。
$ cd gitlabhq $ sudo easy_install pygments $ echo "USERNAME ALL = (git) NOPASSWD: /bin/rm" | sudo tee -a /etc/sudoers $ sudo gem install bundler $ sudo bundle An error occured while installing nokogiri (1.5.0), and Bundler cannot continue. Make sure that `gem install nokogiri -v '1.5.0'` succeeds before bundling.
nokogiriをインストールしないといけないらしいのでインストールします。
$ sudo gem install nokogiri -v 1.5.0
再度bundleを実行
$ sudo bundle An error occured while installing linecache19 (0.5.12), and Bundler cannot continue. Make sure that `gem install linecache19 -v '0.5.12'` succeeds before bundling.
linecache19のインストールに失敗します。
$ sudo gem install linecache19 -v '0.5.12' Building native extensions. This could take a while... ERROR: Error installing linecache19: ERROR: Failed to build gem native extension. /usr/local/ruby/1.9.2/bin/ruby extconf.rb *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/ruby/1.9.2/bin/ruby:29:in `require': no such file to load -- openssl (LoadError) from :29:in `require' from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/net/https.rb:92:in ` ' from :29:in `require' from :29:in `require' from /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/contrib/uri_ext.rb:11:in ` ' from :29:in `require' from :29:in `require' from /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/ruby_core_source.rb:6:in ` ' from :33:in `require' from :33:in `rescue in require' from :29:in `require' from extconf.rb:2:in ` ' Gem files will remain installed in /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/linecache19-0.5.12 for inspection. Results logged to /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/linecache19-0.5.12/ext/trace_nums/gem_make.out
opensslが組み込まれていないためにインストールがこけているようなのでrubyに組み込む。
$ cd /var/install/ruby-1.9.2-p290/ext/openssl $ ruby extconf.rb $ make $ sudo make install
再度linecache19インストール
$ sudo gem install linecache19 Building native extensions. This could take a while... ERROR: Error installing linecache19: ERROR: Failed to build gem native extension. /usr/local/ruby/1.9.2/bin/ruby extconf.rb checking for vm_core.h... no checking for vm_core.h... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/ruby/1.9.2/bin/ruby --with-ruby-dir --without-ruby-dir --with-ruby-include --without-ruby-include=${ruby-dir}/include --with-ruby-lib --without-ruby-lib=${ruby-dir}/lib /usr/local/ruby/1.9.2/lib/ruby/1.9.1/net/http.rb:644:in `initialize': getaddrinfo: Temporary failure in name resolution (SocketError) from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/net/http.rb:644:in `open' from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/net/http.rb:644:in `block in connect' from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/timeout.rb:44:in `timeout' from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/timeout.rb:89:in `timeout' from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/net/http.rb:644:in `connect' from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/net/http.rb:637:in `do_start' from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/net/http.rb:626:in `start' from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/net/http.rb:1168:in `request' from /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/contrib/uri_ext.rb:239:in `block in read' from /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/contrib/uri_ext.rb:286:in `connect' from /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/contrib/uri_ext.rb:234:in `read' from /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/contrib/uri_ext.rb:128:in `download' from /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/ruby_core_source.rb:55:in `block in create_makefile_with_core' from /usr/local/ruby/1.9.2/lib/ruby/1.9.1/tempfile.rb:320:in `open' from /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/ruby_core_source.rb:51:in `create_makefile_with_core' from extconf.rb:19:in `' Requesting http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz Gem files will remain installed in /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/linecache19-0.5.12 for inspection. Results logged to /usr/local/ruby/1.9.2/lib/ruby/gems/1.9.1/gems/linecache19-0.5.12/ext/trace_nums/gem_make.out
次はvm_core.hがないのでエラーが発生します。
$ sudo gem install linecache19 -v '0.5.12' -- --with-ruby-include=/var/install/ruby-1.9.2-p290
インストール時のオプション--with-ruby-includeでrubyのソースコードのディレクトリを指定してインストールを実行すると成功します。
再度bundle実行
$ sudo bundle An error occured while installing ruby-debug-base19 (0.11.25), and Bundler cannot continue. Make sure that `gem install ruby-debug-base19 -v '0.11.25'` succeeds before bundling.
ruby-debug-base19も必要らしいです。
$ sudo gem install ruby-debug-base19 -v '0.11.25' -- --with-ruby-include=/var/install/ruby-1.9.2-p290
再度実行
$ sudo bundle ・・・略 Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
成功しました。
rakeを実行します。
$ sudo bundle exec rake db:setup RAILS_ENV=production -- create_table("issues", {:force=>true}) -> 0.2758s -- create_table("keys", {:force=>true}) -> 0.1384s -- create_table("notes", {:force=>true}) -> 0.1364s -- create_table("projects", {:force=>true}) -> 0.1212s -- create_table("snippets", {:force=>true}) -> 0.1441s -- create_table("users", {:force=>true}) -> 0.1383s -- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true}) -> 0.2079s -- add_index("users", ["reset_password_token"], {:name=>"index_users_on_reset_password_token", :unique=>true}) -> 0.3951s -- create_table("users_projects", {:force=>true}) -> 0.1793s -- initialize_schema_migrations_table() -> 0.3222s -- assume_migrated_upto_version(20111025134235, ["/var/git/gitlabhq/db/migrate"]) -> 3.4068s $ sudo bundle exec rake db:seed_fu RAILS_ENV=production == Seed from /var/git/gitlabhq/db/fixtures/production/001_admin.rb Administrator account created: [email protected] password......5iveL!fe
これでインストール完了です。
GitLab起動
$ cd /var/git/gitlab $ rails s -e production -p 80
無事起動。
http://hostname/にアクセスしてrake実行完了した際に表示されたlogin名とパスワードを入力してログイン。
ここまででとりあえず動作させることには成功しました。
config/gitosis.ymlの編集
起動はしましたが、このままではうまくいきません。
gitlabhqのディレクトリ内のconfig/gitosis.ymlを正しく環境に合わせて設定する必要があります。
#admin_uri: git@localhost:gitosis-admin.git admin_uri: git@hostname:gitosis-admin.git base_path: /home/git/repositories/ #host: localhost host: hostname git_user: git
admin_uriやhostの値を正しいホスト名またはIPアドレスに設定します。
これによって、GitLabの画面内に表示するPath名などが正しく表示されます。
最後にGitLabのサーバを再起動して下さい。
以上で構築は完了です。
次は、Projectの登録やUser登録の方法を紹介します。(GitLabにgitリポジトリを登録し開発できるようにしてみる - ike-daiの日記)