dogwood008の開発メモ!

最近のマイブームは機械学習, Ruby on Rails。中でも機械学習を使った金融商品の自動取引に興味があります。

さくらのVPSでRuby on Rails3を走らせる "Ruby on Rails 3" on SAKURA's VPS

引き続き、http://d.hatena.ne.jp/nakakoh/20101230/1293721678http://www.happytrap.jp/blogs/2010/11/03/4146/を参考に、作業していきます。。。

gitをインストールするために、rpmforgeなるものをインストール。
さくらのVPSがデフォルトで入れていたOSはCentOS 5.5だったので、
http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
をチョイス。

$ wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
# rpm -ivh rpmforge-release-0.5.2-2.el5.rf.i386.rpm

要るものを根こそぎインストール。
# yum install git vim-common vim-enhanced mysql-devel readline-devel openssl-devel -y

checkinstallというアプリケーションが便利らしい。
$ wget http://asic-linux.com.mx/~izto/checkinstall/files/source/checkinstall-1.6.2.tar.gz
$ tar xzvf checkinstall-1.6.2.tar.gz
$ cd checkinstall-1.6.2
# make
# make install
# /usr/local/sbin/checkinstall

checkinstall 1.6.2, Copyright 2009 Felipe Eduardo Sanchez Diaz Duran
           This software is released under the GNU GPL.


The checkinstallrc file was not found at:
/usr/local/sbin/../checkinstallrc


Assuming default values.


The package documentation directory ./doc-pak does not exist. 
Should I create a default set of package docs?  [y]: 


Preparing package documentation...OK


Please choose the packaging method you want to use.
Slackware [S], RPM [R] or Debian [D]? R




**************************************
**** RPM package creation selected ***
**************************************


This package will be built according to these values: 


1 -  Summary: [ CheckInstall installations tracker, version 1.6.2 ]
2 -  Name:    [ checkinstall ]
3 -  Version: [ 1.6.2 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ Applications/System ]
7 -  Architecture: [ x86_64 ]
8 -  Source location: [ checkinstall-1.6.2 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ checkinstall ]


Enter a number to change any of them or press ENTER to continue: 


Installing with make install...


========================= Installation results ===========================
ERROR: ld.so: object '/usr/local/lib64/installwatch.so' from LD_PRELOAD cannot be preloaded: ignored.
(中略)
Deleting temp dir...OK




**********************************************************************


 Done. The new package has been saved to


 /usr/src/redhat/RPMS/x86_64/checkinstall-1.6.2-1.x86_64.rpm
 You can install it in your system anytime using: 


      rpm -i checkinstall-1.6.2-1.x86_64.rpm


**********************************************************************

$ sudo rpm -ivh /usr/src/redhat/RPMS/x86_64/checkinstall-1.6.2-1.x86_64.rpm  



Rubyは、パッケージでは古いので、ソースからコンパイル。
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p330.tar.gz
$ tar xzvf ruby-1.8.7-p330.tar.gz
$ cd xzvf ruby-1.8.7-p330
# ./configure
# sudo make
# /usr/local/sbin/checkinstall
y
R
# rpm -i /usr/src/redhat/RPMS/x86_64/ruby-1.8.7-p330-1.x86_64.rpm

$ ruby -v
ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux]
おっけーですね。


国際化に対応。

# vim /etc/sysconfig/i18n 
LANG="ja_JP.UTF-8"
SYSFONT="latarcyrheb-sun16"


rubygemとRails3、Passengerをインストール。
$ wget http://production.cf.rubygems.org/rubygems/rubygems-1.5.0.tgz
$ tar xzvf rubygems-1.5.0.tgz 
$ cd rubygems-1.5.0
# ruby setup.rb

$ gem -v
1.5.0

# gem install rails --no-ri --no-rdoc
# gem install passenger
# passenger-install-apache2-module

 * GNU C++ compiler... found at /usr/bin/g++
 * Curl development headers with SSL support... not found
 * OpenSSL development headers... found
 * Zlib development headers... found
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/local/bin/rake
 * rack... found
 * Apache 2... not found
 * Apache 2 development headers... not found
 * Apache Portable Runtime (APR) development headers... not found
 * Apache Portable Runtime Utility (APU) development headers... not found

# yum install curl-devel httpd httpd-devel apr-devel apr-util-devel
# passenger-install-apache2-module
# vim /etc/httpd/conf/httpd.conf

   LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.2
   PassengerRuby /usr/local/bin/ruby



   ServerName www.yourhost.com
   DocumentRoot /var/www/html/rails_app/public
  
      AllowOverride all
      Options -MultiViews
  


# /etc/init.d/httpd restart
これで、Passengerの設定は終わり。

次は、各Railsアプリに固有の必要なgemのインストール。
$ cd RAILS_ROOT
$ bundle install

Fetching source index for http://rubygems.org/
Using rake (0.8.7) 
Using abstract (1.0.0) 
(中略)
Using simple_oauth (0.1.3) 
Installing sqlite3-ruby (1.2.1) with native extensions /usr/local/lib/ruby/site_ruby/1.8/rubygems/installer.rb:529:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)


        /usr/local/bin/ruby extconf.rb 
checking for sqlite3.h... no


make
make: *** No rule to make target `ruby.h', needed by `sqlite3_api_wrap.o'.  Stop.




Gem files will remain installed in /home/kit/hagetui/vendor/bundle/ruby/1.8/gems/sqlite3-ruby-1.2.1 for inspection.
Results logged to /home/kit/hagetui/vendor/bundle/ruby/1.8/gems/sqlite3-ruby-1.2.1/ext/sqlite3_api/gem_make.out
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/installer.rb:482:in `each'
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/installer.rb:482:in `build_extensions'
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/installer.rb:156:in `install'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/source.rb:96:in `install'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/installer.rb:55:in `run'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/spec_set.rb:12:in `each'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/spec_set.rb:12:in `each'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/installer.rb:44:in `run'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/installer.rb:8:in `install'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/cli.rb:226:in `install'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/task.rb:22:in `send'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/task.rb:22:in `run'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor.rb:246:in `dispatch'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/base.rb:389:in `start'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.10/bin/bundle:13
        from /usr/local/bin/bundle:19:in `load'
        from /usr/local/bin/bundle:19

とまっちゃいました。。。SQLiteのヘッダファイルがないようなので、インストールしてみます。
$ yum install sqlite-devel
でいけました^^