linux系统的ruby安装 ZT

网站: JavaEye 作者: LIMIMGJIE 链接:http://www.javaeye.com/topic/153203 发表时间: 2008年01月04日

声明:本文系JavaEye网站发布的原创文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!

linux系统的ruby安装

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。