Redhat系列下安装rubyOnRails的生产环境.doc_第1页
Redhat系列下安装rubyOnRails的生产环境.doc_第2页
Redhat系列下安装rubyOnRails的生产环境.doc_第3页
Redhat系列下安装rubyOnRails的生产环境.doc_第4页
Redhat系列下安装rubyOnRails的生产环境.doc_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Redhat系列下安装rubyOnRails的生产环境 简单描述 这里介绍的内容是基于redhat系列(rhel或者centos)的。由于各个发行版的情况都有不一样的地方,如果使用的是其他发行版本请自行google。另外我测试的环境是gcc4.x,这里使用的数据库是oracle,mysql的内容以后再加。 主要软件及用途如下:ruby1.8.7-p72-mbari(ruby解释器,用来解释ruby语言用的)rails2.1.2(一个用ruby写的一站式快速开发框架)oracle10g(数据库)ruby-oci8(用来和oracle交互用的ruby库)ruby-odbc(用来和odbc交互用的ruby库)RMagick(图形处理库)memcached(流行的分布式缓存服务器)lighttpd/nginx(web前端服务器)mongrel/thin(用来处理动态请求的http服务器)fcgi(fast cgi运行模块) 一般是使用多进程单线程的运行方式,部署在lighttpd+fcgi(非常高效,安装麻烦),或者nginx+mongrel/thin(高效,安装简单)的架构上。 安装ruby /wiki/rails_deployment/1296-deploy-rails-on-linux/news/4592-resolve-memory-leaks-ruby-patch-release下载ruby 1.8.7-p72.tar.gz和MBARIp72patches.tar.gztar zxvf ruby-1.8.7-p72.tar.gztar zxvf MBARIp72patches.tar.gz解压打补丁命令:MBARIp72patches/apply ruby-1.8.7-p72编译ruby,如下:cd ruby-1.8.7-p72CFLAGS=-O2 -fno-stack-protector -mpreferred-stack-boundary=2 ./configure -prefix=/usr/local/ruby-1.8.7-p72make & make install备注:如果没有gcc,需要yum install gcc,如果是gcc3.x,需要去掉-fno-stack-protector 编译之后,编辑/etc/profile,加入 export RUBY_HOME=/usr/local/ruby-1.8.7-p72PATH=$RUBY_HOME/bin:$PATH 执行source /etc/profile,并使用ruby -v进行验证: rootlocalhost ext# ruby -vruby 1.8.7 (2009-3-1 mbari 8B/0x8770 on patchlevel 72) i686-linux 下载rubygems-1.3.1.tgz tar zxvf rubygems-1.3.1.tgzcd rubygems-1.3.1ruby setup.rb并使用gem -v进行验证:rootlocalhost ext# gem -v1.3.1 安装ruby-ext:zilb,readline或者openssl cd ruby-1.8.7-p72/ext/zlibruby extconf.rb -with-zlib-include=/usr/include -with-zlib-lib=/usr/libmake & make install 如果出错,可能需要进行yum install zlib-develcd ruby-1.8.7-p72/ext/readlineruby extconf.rbmake & make install 如果出错,可能需要进行yum install readline-develcd ruby-1.8.7-p72/ext/opensslruby extconf.rbmake & make install 如果出错,可能需要进行yum install openssl-devel 安装各式各样的gem gem source -a gem install rails -version 2.1.2 -no-rdoc -no-rigem install mongrel_cluster -no-rdoc -no-rigem install memcache-client -version 1.7.3 -no-rdoc -no-riyum install libxml2*gem install libxml-ruby -version 1.1.3 -no-rdoc -no-rigem install spreadsheet -version -no-rdoc -no-rigem install uuidtools -version 2.0.0 -no-rdoc -no-rigem install composite_primary_keys -version 1.1.0 -no-rdoc -no-rigem install rack -no-rdoc -no-rigem install thin -no-rdoc -no-rigem install dbi -version 0.4.2 -no-rdoc -no-rigem install dbd-odbc -version 0.2.5 -no-rdoc -no-ri备注:如果提示g+命令未找到,则yum install gcc-c+ 安装oracle即时客户端 rpm -ivh oracle-instantclient-basic--1.i386.rpmrpm -ivh oracle-instantclient-devel--1.i386.rpm可选:#rpm -ivh oracle-instantclient-sqlplus--1.i386.rpm#rpm -ivh oracle-instantclient-jdbc--1.i386.rpm 修改/etc/profile,添加 export NLS_LANG=American_America.ZHS16GBKexport LD_LIBRARY_PATH=/usr/lib/oracle//client/libPATH=$LD_LIBRARY_PATH:$PATH 执行source /etc/profile 下载ruby-oci8-1.0.6.tar.gz tar zxvf ruby-oci8-1.0.6.tar.gz cd ruby-oci8-1.0.6ruby setup.rb configruby setup.rb setupruby setup.rb install 验证ruby-oci8安装情况 rootlocalhost i686-linux# irbirb(main):001:0 require oci8= true如果出错的话(cannot restore segment prot after reloc: Permission denied), 需要执行/usr/sbin/setenforce 0来临时关闭selinux 也可以修改/etc/selinux/config把enforcing修改成disabled并重启安装odbc 有时候我们需要用到sqlserver这样的东西,在linux上弄这个还是比较麻烦的。我们采取的方案是unixODBC+freeTDS+ruby-odbc+dbi(dbd-odbc)的方式(我们并不打算使用orm)。首先需要安装的是freeTDS(*unix下用来访问sybase和sqlserver的工具)和unixODBC(用来提供ODBC,在这里就是利用freeTDS的驱动来提供一个DSN)yum install unixODBC-devel freetds-devel安装后可以测试一下rootlocalhost # tsql -S 33 -U sa -P softsckjlocale is zh_CN.UTF-8locale charset is UTF-81 use jw2 select count(*) from ttuition3 go2628461然后安装ruby-odbc,在http:/www.ch-werner.de/rubyodbc/下载ruby-odbc-0.9997.tar.gztar zxvf ruby-odbc-0.9997.tar.gzcd ruby-odbc-0.9997ruby extconf.rbmake & make install接下去进行配置:修改/etc/freetds.confMyServer2k host = 33 port = 1433 tds version = 8.0这里修改host,主要是为了可以引用到这个MyServer2K修改/etc/odbcinst.ini(这是用来定义各种各样的Driver的地方)FreeTDSDescription = ODBC for MS SqlServerDriver = /usr/lib/libtdsodbc.soSetup = /usr/lib/libtdsS.soFileUsage = 1修改/etc/odbc.ini(这里就是配置DSN的地方)JWDescription = jwDriver = FreeTDSServername = MyServer2kDatabase = jwUID = saPWD = softsckj注意到这里的MyServer2k引用的是freetds.conf里边定义的。其实按道理这里直接使用ip就可以的,可惜的是,在freetds0.64里边设置ip的话,根本不起作用。最后,简单写个脚本测试一下:rootlocalhost # vi test.rb#!/bin/env rubyrequire rubygemsrequire dbirequire odbcDBI.connect(dbi:ODBC:JW,sa,softsckj) do |dbh| dbh.select_all(select top 10 * from ttuition) do |row| p row.join(,) endend能够得出结果就表示配置成功了。安装memcached 下载libevent-1.4.12-stable.tar.gz和memcached-1.4.0.tar.gz tarzxvf libevent-1.4.12-stable.tar.gzcd libevent-1.4.12-stable./configure -prefix=/usr/local/libevent-1.4.12make & make installcp /usr/local/libevent-1.4.12/lib/libevent-1.4.so.2 /usr/lib/tar zxvf memcached-1.4.0.tar.gzcd memcached-1.4.0./configure -with-libevent=/usr/local/libevent-1.4.12 -prefix=/usr/local/memcached-1.4.0make & make install 运行并验证 rootlocalhost bin# /usr/local/memcached-1.4.0/bin/memcached -d -m 256 -p 11211 -u rootrootlocalhost bin# telnet localhost 11211Trying .Connected to localhost.localdomain ().Escape character is .stats STAT pid 5075STAT uptime 155STAT time 1248845966STAT version 1.4.0 安装nginx 下载nginx-0.7.61.tar.gztar zxvf nginx-0.7.61.tar.gzcd nginx-0.7.61./configure -prefix=/usr/local/nginx-0.7.61 -user=nobody -group=nobody -without-poll_module -with-http_stub_status_module -with-http_gzip_static_module -with-http_realip_modulemake & make install 配置/usr/local/nginx-0.7.61/conf/nginx.conf,示例: user nobody;worker_processes 1;error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events use epoll;worker_connections 65535;http include mime.types;default_type application/octet-stream;#log_format main $remote_addr - $remote_user $time_local $request # $status $body_bytes_sent $http_referer # $http_user_agent $http_x_forwarded_for;#access_log logs/access.log main;access_log off;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;gzip on;gzip_min_length 1k;gzip_buffers 4 8k;gzip_http_version 1.1;gzip_types text/plain application/x-javascript text/css text/html application/xml image/jpeg image/png image/gif;upstream backend server :3000 weight=1;server :3001 weight=1;server :3002 weight=1;server :3003 weight=1;server :3004 weight=1; server listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / #internal;proxy_pass http:/backend/;#proxy_store on;proxy_redirect off;proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;client_max_body_size 10m;client_body_buffer_size 128k;proxy_connect_timeout 90;proxy_send_timeout 90;proxy_read_timeout 90;proxy_buffer_size 4k;proxy_buffers 4 32k;proxy_busy_buffers_size 64k;proxy_temp_file_write_size 64k;index index.html index.php index.htm;location /NginxStatus stub_status on;access_log on;auth_basic NginxStatus;location * .+.(jpg|jpeg|gif|css|png|js|ico)$ root /var/www/gst/public;index index.php;access_log off;expires 14d;#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html root html;# proxy the PHP scripts to Apache listening on :80#location .php$ # proxy_pass ;# pass the PHP scripts to FastCGI server listening on :9000#location .php$ # root html;# fastcgi_pass :9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;# deny access to .htaccess files, if Apaches document root# concurs with nginxs one#location /.ht # deny all;# another virtual host using mix of IP-, name-, and port-based configuration#server # listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / # root html;# index index.html index.htm;# # HTTPS server#server # listen 443;# server_name localhost;# ssl on;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_timeout 5m;# ssl_protocols SSLv2 SSLv3 TLSv1;# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;# ssl_prefer_server_ciphers on;# location / # root html;# index index.html index.htm;# #测试并运行和关闭 /usr/local/nginx-0.7.61/sbin/nginx -t/usr/local/nginx-0.7.61/sbin/nginx -c /usr/local/nginx-0.7.61/conf/nginx.conf&killall -HUP nginx 安装RMagick 检测图片支持,如果检测不到的话,需要通过yum来安装rpm -qa | grep libpngrpm -qa | grep libpng-develrpm -qa | grep libjpegrpm -qa | grep gd-devel如果你希望支持tiff格式,还应该检查rpm -qa | grep libtiff下载ImageMagick-6.5.4-6.tar.bz2 tar jxvf ImageMagick-6.5.4-6.tar.bz2cd ImageMagick-6.5.4-6./configure -prefix=/usr/local/ImageMagick-6.5.4-6make & make install 编辑/etc/profile里面的PATH环境变量,加入: export PATH=/usr/local/ImageMagick-6.5.4-6/bin:$PATH 编辑/etc/ld.so.conf,加入: /usr/local/ImageMagick-6.5.4-6/lib执行命令ldconfig将ImageMagick的库加入系统联接库执行命令source /etc/profile让文件生效,最后验证 convert logo: logo.gif 看是否正确生成一个logo.gif的图片文件 下载RMagick-2.10.0.tar.bz2 tar jxvf RMagick-2.10.0.tar.bz2cd RMagick-2.10.0ruby setup.rb安装完成还是不能使用的话,可以下载rmagick-2.10.0.gem来安装 gem install rmagick-2.10.0.gem -no-rdoc -no-ri 安装fcgi 由于ruby的fcgi支持库需要在编译的时候联接FCGI的系统库,因此我们需要先安装FCGI库,下载FCGI源代码发行包:/dist/tar xzvf fcgi-2.4.0.tar.gzcd fcgi-2.4.0./configure -prefix=/usr/local/fcgi-2.4.0make & make install 然后就可以安装ruby的fcgi支持库了,下载ruby-fcgi-0.8.7.tar.gz tar xzvf ruby-fcgi-0.8.7.tar.gzcd ruby-fcgi-0.8.7ruby install.rb config - -with-fcgi-dir=/usr/local/fcgi-2.4.0ruby install.rb setupruby install.rb install 在public下面新建dispatch.sh用来启动fcgi,如下: #!/bin/sh DISPATCH_PATH=/var/www/gst/public/dispatch.fcgi SOCKET_PATH=/tmpPID_PATH=/tmpRAILS_ENV=production export RAILS_ENV case $1 in start) for num in 0 1 2 3 4 5 6 7 8 9 do /usr/local/lighttpd-1.4.23/bin/spawn-fcgi -f $DISPATCH_PATH -s $SOCKET_PATH/rails$num.sock -P $PID_PATH/rails$num.pid -u lighttpd -g lighttpd done ; stop) killall -9 dispatch.fcgi ; restart) $0 stop $0 start ; *) echo Usage: dispatch.sh start|stop|restart ; esac exit 0这样就可以通过./dispatch.sh start来启动10个fcgi进程了,而lighttpd就是把请求交给这10个fcgi进程进行处理的。 安装lighttpd yum install bzip2-develyum install pcre-develyum install gamin-devel下载lighttpd-1.4.23.tar.gztar xzvf lighttpd-1.4.23.tar.gzcd lighttpd-1.4.23./configure -prefix=/usr/local/lighttpd-1.4.23 -with-fam完毕以后,会给出一个激活的模块和没有激活模块的清单,可以检查一下,是否自己需要的模块都已经激活,在enable的模块中一定要有 “mod_rewrite”这一项,否则重新检查pcre是否安装.最后编译:make & make install 最后把/usr/local/lighttpd-1.4.23/lib添加到/etc/ld.so.conf里边去并执行ldconfigcp doc/rc.lighttpd.redhat /etc/init.d/lighttpdmkdir /etc/lighttpdcp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf然后修改/etc/init.d/lighttpd,把LIGHTTPD_BIN=/usr/sbin/lighttpd改为LIGHTTPD_BIN=/usr/local/lighttpd-1.4.23/sbin/lighttpd 配置/etc/lighttpd/lighttpd.conf,示例: # lighttpd configuration file# use it as a base for lighttpd 1.0.0 and above# $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $# Options you really have to take care of # modules to load# at least mod_access and mod_accesslog should be loaded# all other module should only be loaded if really neccesary# - saves some time# - saves memoryserver.modules = (mod_rewrite,# mod_redirect,# mod_alias,mod_access,# mod_cml,# mod_trigger_b4_dl,# mod_auth,# mod_status,# mod_setenv,mod_fastcgi,# mod_proxy,mod_simple_vhost,# mod_evhost,# mod_userdir,mod_cgi,mod_compress,# mod_ssi,# mod_usertrack,# mod_expire,# mod_secdownload,# mod_rrdtool,#mod_accesslog)# a static document-root, for virtual-hosting take look at the# server.virtual-* optionsserver.document-root = /var/www/gst/public# where to send error-messages toserver.errorlog = /var/log/lighttpd/error.log# files to check for if ./ is s = ( index.php, index.html,index.htm, default.htm )# set the event-handler (read the performance section in the manual)# server.event-handler = freebsd-kqueue # needed on OS X# mimetype mappingmimetype.assign = (.pdf = application/pdf,.sig = application/pgp-signature,.spl = application/futuresplash,.class = application/octet-stream,.ps = application/postscript,.torrent = application/x-bittorrent,.dvi = application/x-dvi,.gz = application/x-gzip,.pac = application/x-ns-proxy-autoconfig,.swf = application/x-shockwave-flash,.tar.gz = application/x-tgz,.tgz = application/x-tgz,.tar = application/x-tar,.zip = application/zip,.mp3 = audio/mpeg,.m3u = audio/x-mpegurl,.wma = audio/x-ms-wma,.wax = audio/x-ms-wax,.ogg = application/ogg,.wav = audio/x-wav,.gif = image/gif,.jar = application/x-java-archive,.jpg = image/jpeg,.jpeg = image/jpeg,.png = image/png,.xbm = image/x-xbitmap,.xpm = image/x-xpixmap,.xwd = image/x-xwindowdump,.css = text/css,.html = text/html,.htm = text/html,.js = text/javascript,.asc = text/plain,.c = text/plain,.cpp = text/plain,.log = text/plain,.conf = text/plain,.text = text/plain,.txt = text/plain,.dtd = text/xml,.xml = text/xml,.mpeg = video/mpeg,.mpg = video/mpeg,.mov = video/quicktime,.qt = video/quicktime,.avi = video/x-msvideo,.asf = video/x-ms-asf,.asx = video/x-ms-asf,.wmv = video/x-ms-wmv,.bz2 = application/x-bzip,.tbz = application/x-bzip-compressed-tar,.tar.bz2 = application/x-bzip-compressed-tar,# default mime type = application/octet-stream,)# Use the Content-Type extended attribute to obtain mime type if possible#mimetype.use-xattr = enable# send a different Server: header# be nice and keep it at lighttpd# server.tag = lighttpd# accesslog module#accesslog.filename = /var/log/lighttpd/access.log# deny access the file-extensions# is for backupfiles from vi, emacs, joe, .# .inc is often used for code includes which should in general not be part# of the document-rooturl.access-deny = ( , .inc )$HTTPurl = .pdf$ server.range-requests = disable# which extensions should not be handle via static-file transfer# .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgistatic-file.exclude-extensions = ( .php, .pl, .fcgi )# Options that are good to be but not neccesary to be changed # bind to port (default: 80)server.port = 80# bind to localhost (default: all interfaces)server.bind = # error-handler for status 404#server.error-handler-404 = /error-handler.html#server.error-handler-404 = /error-handler.php# to help the rc.scriptsserver.pid-file = /var/log/lighttpd/lighttpd.pidserver.stat-cache-engine = famserver.event-handler = work-backend = linux-sendfileserver.max-request-size = 10240server.max-fds = 2048# virtual hosts# If you want name-based virtual hosting add the next three settings and load# mod_simple_vhost# document-root =# virtual-server-root + virtual-server-default-host + virtual-server-docroot# or# virtual-server-root + http-host + virtual-server-docroot#simple-vhost.server-root = /srv/www/vhosts/#simple-vhost.default-host = #simple-vhost.document-root = /htdocs/# Format: .html# - ./status-404.html for File not found#server.errorfile-prefix = /usr/share/lighttpd/errors/status-#server.errorfile-prefix = /srv/www/errors/status-# virtual directory listings#dir-listing.activate = enable# select encoding for directory listings#dir-listing.encoding = utf-8# enable debugging#debug.log-request-header = enable#debug.log-response-header = enable#debug.log-request-handling = enable#debug.log-file-not-found = enable# only root can use these options# chroot() to directory (default: no chroot() )#server.chroot = /# change uid to (default: dont care)server.username = lighttpd# change uid to (default: dont care)server.groupname = lighttpd# compress modulecompress.cache-dir = /tmp/compress.filetype = (text/plain, text/html,text/javascript,text/css)# proxy module# read proxy.txt for more info#proxy.server = ( .php =# ( localhost =# (# host = 01,# port = 80# )# )# )# fastcgi module# read

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论