歡迎您光臨本站 註冊首頁

Linux操作系統下輕鬆配置Ruby的程序環境

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
   

Ruby安裝包

下載地址:http://www.ruby-lang.org/en/downloads/

ruby-1.8.6-p111.tar.gz

解壓並安裝:

tar -xvzf ruby-1.8.6-p111.tar.gz

cd ruby-1.8.6-p111

./configure -prefix=/opt/modules/ruby

make

make install

操作系統PATH路徑:

export PATH=/opt/modules/ruby/bin:$PATH

 

rails遠程安裝:

gem下載地址:http://rubyforge.org/projects/rubygems/

解壓並安裝:

tar xzvf rubygems-1.0.1.tgz

cd rubygems-1.0.1/

ruby setup.rb

ruby/bin/gem install rails --remote

mysql_ruby驅動安裝

下載地址:http://www.tmtm.org/en/mysql/ruby/

解壓並安裝:

tar -xvzf mysql-ruby-2.7.4.tar.gz

cd mysql-ruby-2.7.4

ruby extconf.rb --with-mysql-dir=/opt/modules/mysql/

make && make install

fast-cgi安裝:

下載地址:http://www.fastcgi.com/dist/

解壓並安裝:

tar xzvf fcgi-2.4.0.tar.gz

cd fcgi-2.4.0

./configure --prefix=/opt/modules/fcgi

make && make install

安裝ruby的fcgi支持庫:

tar xzvf ruby-fcgi-0.8.7.tar.gz

cd ruby-fcgi-0.8.7

ruby install.rb config -- --with-fcgi-include=/opt/modules/fcgi/include --with-fcgi-lib=/opt/modules/fcgi/lib

ruby install.rb setup

ruby install.rb install

 

Lighttpd安裝:

下載地址:http://www.lighttpd.net/download/

注意: 安裝前要檢查linux中的pcre,在RedHat中會默認安裝pcre-4.5-3.2.RHEL4,這個版本不支持lighttpd.

必須下載另外兩個rpm,grep-2.5.1-32.2.i386.rpm和pcre-devel-4.5-3.2.SEL4.i386.rpm,

下載地址:http://scientificlinux.physik.uni-muenchen.de/mirror/scientific/43/i386/errata/fastbugs/RPMS/grep-2.5.1-32.2.i386.rpm

 

下載地址:ftp://ftp.pbone.net/mirror/www.startcom.org/AS-4.0.0/os/i386/StartCom/RPMS/pcre-devel-4.5-3.2.SEL4.i386.rpm

 

安裝命令為:rpm -ivh rpm包名

 

解壓並安裝:

tar xzvf lighttpd-1.4.18.tar.gz

./configure --prefix=/opt/modules/lighttpd

make && make install

 

配置環境:

1.將lighttpd的配置文件放到/etc/lighttpd/

cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd

mkdir /etc/lighttpd

cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf

 

2.將啟動伺服器的啟動文件放入到用戶的目錄中

cp doc/rc.lighttpd.redhat /etc/init.d/lighttpd

編輯此文件:

LIGHTTPD_BIN=/usr/sbin/lighttpd

改為

LIGHTTPD_BIN=/usr/local/lighttpd/sbin/lighttpd

 

希望伺服器啟動的時候就啟動lighttpd,那麼:

chkconfig lighttpd on

 

配置Lighttpd

 

修改/etc/lighttpd/lighttpd.conf

 

1)server.modules

取消需要用到模塊的註釋,mod_rewrite,mod_access,mod_fastcgi,mod_simple_vhost,mod_cgi,mod_compress,mod_accesslog是一般需要用到的。

 

2)server.document-root, server.error-log,accesslog.filename需要指定相應的目錄

 

3)用什麼許可權來運行lighttpd,默認將使用root用戶進行運行。

server.username = "nobody"

server.groupname = "nobody"

從安全形度來說,不建議用root許可權運行web server,可以自行指定普通用戶許可權。

 

4)靜態文件壓縮

compress.cache-dir = "/tmp/lighttpd/cache/compress"

compress.filetype = ("text/plain", "text/html","text/javascript","text/css")

可以指定某些靜態資源類型使用壓縮方式傳輸,節省帶寬,對於大量AJAX應用來說,可以極大提高頁面載入速度。

 

安裝過程中遇到的一些問題:(安裝花緒)

1.在安裝rails的過程中,由於需要遠程安裝rails的時候,但是安裝不成功,

命令提示:

ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)

getaddrinfo: Temporary failure in name resolution (SocketError)

getting size of http://gems.rubyforge.org/Marshal.4.8

原因是此伺服器沒設置DNS,不能對外訪問網路。

解決方法:

 

 

#>vi /etc/resolv.conf   nameserver 202.106.46.151   nameserver 202.106.196.115   nameserver 211.98.2.4   nameserver 211.98.4.1

 

2.安裝lighttpd時,由於原來的pcre包不支持此服務,需要安裝一個linux內核包pcre-devel-4.5-3.2.SEL4.i386.rpm,

但是不能正常安裝。

命令提示:

warning: pcre-devel-4.5-3.2.SEL4.i386.rpm: V3 DSA signature: NOKEY, key ID 652e84dc

error: Failed dependencies:

pcre = 4.5-3.2.SEL4 is needed by pcre-devel-4.5-3.2.SEL4.i386

 

原因是此安裝包不能直接進行安裝,必須安裝另一個grep的rpm包,才能正常安裝。

解決方法:

 

 

#>rpm -ivh grep-2.5.1-32.2.i386.rpm   #>rpm -ivh pcre-devel-4.5-3.2.SEL4.i386.rpm

 

3.lighttpd的配置,服務不能正常啟動,啟動步驟如下:

#>/etc/init.d/lighttpd status

命令提示:

lighttpd dead but pid file exists

在配置過程中由於對配置文件的內容不是很熟悉,所以只好拿可以運行的配置比對,經過調試發現有幾處需要調整,

1)server.pid-file = "/var/run/lighttpd.pid"

此處是當前項目運行時的PID;

2)compress.cache-dir = "/opt/modules/lighttpd/compress"

經處是的目錄需要手動建立,否則載入會失敗!

3)fastcgi.server = (

".fcgi" => (

"rails" => (

"socket" => "/tmp/lighttpd/socket/rails.socket",

"bin-path" => "/opt/pptv-data/pptvCMS/public/dispatch.fcgi",

"bin-environment" => ("RAILS_ENV" => "development"),

"min-procs" => 10,

"max-procs" => 10

)

)

)

上述代碼為新增該服務訪問的項目路徑。此項目會啟動10個進程,會建立10個rails.socket,保證socket建立的所在目錄存在。

項目所在的物理地址是否正確(/opt/pptv-data/pptvCMS/public/dispatch.fcgi)。

4)index-file.names = ( "dispatch.fcgi","index.php","index.html","index.htm", "default.htm" )

新增"dispatch.fcgi"作為訪問頁面。

5)查看項目對應的public/dispatch.fcgi中的第一行是否為當前伺服器的ruby安裝路徑。

ruby安裝路徑:/opt/modules/ruby

dispatch.fcgi中的第一行:#!/opt/modules/ruby/bin/ruby

需要修改的文件包括:dispatch.cgi,dispatch.rb,dispatch.fcgi

 

4 lighttpd的配置正確,服務正常啟動,項目不能正常訪問:

命令提示:

錯誤訪問號500,頁面不存在,

問題的原因,在environment.rb文件中需要指定rails的版本號,

如:

RAILS_GEM_VERSION = '1.2.6' unless defined? RAILS_GEM_VERSION

查看版本發現rails的版本是2.0.2,由於開發時採用的版本為1.2.6,所以需要卸載當前的2.0.2版本,安裝1.2.6版本。

解決方法:

gem uninstall rails

gem install rails --version '=1.2.6'

重新啟動服務,一切OK。

(責任編輯:A6)



[火星人 ] Linux操作系統下輕鬆配置Ruby的程序環境已經有434次圍觀

http://coctec.com/docs/program/show-post-71751.html