24 Jul 2010

在centos上装rubyee,passenger和memcached ,搭建rails环境

流水笔记一则.

我之前已在服务器配置了nginx,php,mysql等,现在先安装ruby企业版

cd /tmp
wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz
tar -xzvf ruby-enterprise-1.8.7-2010.02.tar.gz
cd ruby-enterprise-1.8.7-2010.02
./installer

然后按照提示做

设置一下环境变量 
export PATH=/rubyee/bin:$PATH
接着
ruby -v
gem -v
看到版本号,说明rubyee 安装ok

下来
gem install passenger
passenger-install-nginx-module

按照提示在nginx配置文件里增加:

http {
     ...
     passenger_root /rubyee/lib/ruby/gems/1.8/gems/passenger-2.2.14;
     passenger_ruby /rubyee/bin/ruby;
     ...
}

  server {
     listen 80;
     server_name www.yourhost.com;
     root /somewhere/public;   # <--- be sure to point to 'public'!
     passenger_enabled on;
  }

rails 欧了~

下来开始装 memcached,

memcached 的使用需要libeven的支持

cd /tmp
wget http://www.monkey.org/~provos/libevent-1.4.14a-stable.tar.gz
tar -zxvf libevent-1.4.14a-stable.tar.gz
cd libevent-1.4.14-stable
./configure --prefix=/usr
make && make install

cd /tmp
wget http://memcached.org/latest
tar -zxvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure --prefix=/usr/local
make && make install

 现在可以用
service memcached start  


  service memcached stop  

这两个很骚的命令来管理memcached服务了,欧了~

安装mysql gem
gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

安装 ImageMagick

wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar xvfz ImageMagick.tar.gz
cd ImageMagick*
./configure --disable-static --with-modules --with-gs-font-dir=/usr/share/fonts/type1/gsfonts
make
sudo make install
cd ..
rm -Rf ImageMagick*

wget http://rubyforge.org/frs/download.php/70067/RMagick-2.13.1.tar.bz2
tar -jxf RMagick-2.13.1.tar.bz2
cd RMagick*
./configure --disable-static --with-modules --without-perl --without-magick-plus-plus --with-jpeg=yes --with-png=yes --with-tiff=yes --with-quantum-depth=8  --with-gs-font-dir=/usr/share/fonts/type1/gsfonts
ruby setup.rb
ruby setup.rb install
cd ..
rm -Rf RMagick*

最后 上传 rails 程序
接着 rake gems:install

centos安装rmagick出现以下错误:
libMagickCore.so.2: cannot open shared object file: No such file or directory – /usr/lib/ruby/gems/1.8/gems/rmagick-2.8.0/lib/RMagick2.so
解决办法:

ldconfig /usr/local/lib

错误[memcache-client] Could not load SystemTimer gem, falling back to Ruby's slower/unsafe timeout library: no such file to load -- system_timer
rake aborted!

sudo gem install system_timer

Magick::ImageMagickError (unable to read font `/usr/local/lib/ImageMagick-6.6.3/config//usr/share/fonts/type1/gsfonts/n019003l.pfb' @ error/annotate.c/RenderFreetype/1056: `(null)'):
错误

wget http://sourceforge.net/projects/gs-fonts/files/gs-fonts/8.11%20%28base%2035%2C%20GPL%29/ghostscript-fonts-std-8.11.tar.gz/download
 tar -zxvf ghostscript-fonts-std-8.11.tar.gz
解压后拷贝到需要的目录

24 Sep 2009

rails中的ActiveRecord真性感!

Rails使用的ActiveRecord真性感啊,see see吧

class User < ActiveRecord::Base  
  has_many :articles  
end  
 
class Article < ActiveRecord::Base
  belongs_to :user  
end

然后执行
>> Article.find(1) 会得到延迟加载user对象的sql语句。如下:

SELECT * FROM articles WHERE (articles.id =1) LIMIT 1

当需要访问user对象时,比如用article.user.name会再生成一个sql语句请求数据库。
如果执行
>> Article.find(1,:include => :user) 会得到一次性加载了user的查询

SELECT
articles.`extended_html` AS t0_r6 articles.`excerpt` AS t0_r7
articles.`keywords` AS t0_r8 articles.`allow_pings` AS t0_r10
articles.`allow_comments` AS t0_r9 users.`id` AS t1_r0
articles.`published` AS t0_r11 users.`login` AS t1_r1
articles.`text_filter` AS t0_r12 articles.`id` AS t0_r0
users.`password` AS t1_r2 articles.`user_id` AS t0_r13
articles.`title` AS t0_r1 users.`name` AS t1_r3
articles.`created_at` AS t0_r14 articles.`author` AS t0_r2
users.`email` AS t1_r4 articles.`updated_at` AS t0_r15
articles.`body` AS t0_r3 articles.`permalink` AS t0_r16
articles.`body_html` AS t0_r4 articles.`guid` AS t0_r17
articles.`extended` AS t0_r5
FROM articles LEFT OUTER JOIN users
ON users.id = articles.user_id
WHERE (articles.id = 1)

是不是很优美,很性感涅?

 

29 Aug 2009

Mysql adapter on Rails 2.3.3

安装好Ruby on Rails 2.3.3后,运行简单的页面提示如下错误“The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql”

 gem 了n次也不成,搞了一早上,才google到一个比较山寨的方法解决

1.  download older MySQL client library, for example one from InstantRails: http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll

2.  copy the downloaded file to C:\Ruby\bin (or wherever you installed Ruby) 

3. restart MySQL server

另参考:http://www.ruby-forum.com/topic/160358http://rdc.taobao.com/blog/qa/?p=523