Rails On Slicehost #2

by winson, about 1 year ago.

承續上一次Rails On Slicehost #1未完成的工作。

基本上,無論在一般Debian 4.0環境或任何一家跑Debian的VPS上安裝Ruby on Rails應該都大同小異,甚至在Ubuntu上安裝Ruby on Rails也差不到哪去。

先從ssh登入:

ssh rubyist@your-slice-host-ip-address

Linux debian 2.6.16.29-xen #3 SMP Sun Oct 15 13:15:34 BST 2006 x86_64

The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.

rubyist@debian:~$
設一些常用的捷徑:
rubyist@debian:~$ ln -s .bash_profile .profile
rubyist@debian:~$ pico .profile

# my aliases
alias rehash="source ~/.profile" 
alias saud="sudo apt-get update" 
alias saug="sudo apt-get upgrade" 
alias sapt="apt-cache search" 
alias sagi="sudo apt-get install" 
alias sugi="sudo gem install -y" 
alias restart="sudo /etc/init.d/lighttpd restart" 

rubyist@debian:~$ source ~/.profile
主要修改.bash_profile這個檔案,可以減少一些繁複的指令輸入,這裡主要採用bash作為我習慣的shell。

安裝gcc等套件:

rubyist@debian:~$ sagi build-essential

We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

Password:

Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  binutils cpp cpp-4.1 gcc-4.1 libssp0
Suggested packages:
  binutils-doc cpp-doc gcc-4.1-locales manpages-dev autoconf automake1.9
  libtool flex bison gdb gcc-doc gcc-4.1-doc libc6-dev-i386 lib32gcc1
  lib32ssp0 make-doc-non-dfsg
Recommended packages:
  libc6-dev libc-dev libmudflap0-dev
The following NEW packages will be installed:
  binutils cpp cpp-4.1 gcc gcc-4.1 libssp0 make
0 upgraded, 7 newly installed, 0 to remove and 5 not upgraded.
Need to get 5998kB of archives.
After unpacking 16.2MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
安裝Ruby/Ruby Gems:
rubyist@debian:~$ sagi ruby irb rake rubygems
Ruby Gems是Ruby上頭相當重要且好用的東西,很多Ruby相關套件都以Gem的形式發佈,方便下載、安裝及更新。

由於Ruby Gems改版很快,目前Debian穩定的套件僅提供到0.9版,不如去RubyForge下載最新版0.94來安裝使用。

安裝MySQL/Ruby MySQL Library:

rubyist@debian:~$ sagi mysql-server mysql-client libmysql-ruby

rubyist@debian:~$ irb

irb(main):001:0> require 'mysql'
=> true
irb是Interactive Ruby,一個簡易的Ruby小引擎,這裡主要測試是否可在Ruby下成功引用MySQL Library。

修改MySQL的root密碼:

rubyist@debian:~$ mysqladmin -u root password new-root-password
安裝Ruby on Rails/ Mongrel server:
rubyist@debian:~$ sugi rails
rubyist@debian:~$ sugi mongrel

Select which gem to install for your platform (x86_64-linux)
 1. mongrel 1.0.1 (mswin32)
 2. mongrel 1.0.1 (ruby)
 3. mongrel 1.0 (mswin32)
 4. mongrel 1.0 (ruby)
> 2

Select which gem to install for your platform (x86_64-linux)
 1. fastthread 1.0 (ruby)
 2. fastthread 1.0 (mswin32)
 3. fastthread 0.6.4.1 (ruby)
 4. fastthread 0.6.4.1 (mswin32)
> 1

Building native extensions.  This could take a while...
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
遇到錯誤訊息,安裝Ruby 1.0 Dev版就沒問題。
rubyist@debian:~$ sagi ruby1.8-dev
重裝一次Mongrel:
rubyist@debian:~$ sugi mongrel
安裝Capistrano:
rubyist@debian:~$ sugi capistrano
這個Capistrano實在是又重要、又好用、又方便的工具,也許該寫一本書來探討,這裡先裝起來再說。

安裝MySQL Gem:

rubyist@debian:~$ sugi mysql

Select which gem to install for your platform (x86_64-linux)
 1. mysql 2.7.3 (mswin32)
 2. mysql 2.7.1 (mswin32)
 3. mysql 2.7 (ruby)
 4. mysql 2.6 (ruby)
 5. mysql 2.5.1 (ruby)
 6. Cancel installation
> 3

Building native extensions.  This could take a while...
*** 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.
這裡又遇到錯誤,一樣裝個開發版試試:
rubyist@debian:~$ sagi libmysqlclient15-dev
rubyist@debian:~$ sugi mysql -y
有需要也可以安裝SQLite,一個簡單的小型資料庫:
rubyist@debian:~$ sagi sqlite3 libsqlite3-dev
rubyist@debian:~$ sugi sqlite3-ruby
要求不多的話,到這裡為止就可以跑Ruby on Rails了。

至於安裝Apache或Lighttpd,多半是拿來作為Reverse proxy,負責Load balance,或者也可以使用專門的Reverse proxy server,而拿Apache/Lighttpd來對付靜態網頁。

另外也可以採用Apache/Lighttpd + Fast CGI,再透過Fast CGI載入Ruby on Rails。

事實上,Ruby on Rails的組成架構千變萬化,網路上有許多專家不斷在探討著,這張投影片也清楚分析整個Ruby on Rails架構擴充以及問題解決的方向。

無論哪種程式語言或軟體系統,架構或性能擴充都不是一蹴可既,需要花時間觀察及改善。

現在聽說過誰還在抱怨Twitter速度慢嗎?完全沒有。


  • Posted in Linux, Rails, Ruby, on Monday, June 25, 2007, at 10:25 AM.