九月
29

一、安装 memcached

到这里下载安装并启动(Debian 上我使用的是memcached-1.1.13.tar.gz):

./memcached -d -u root -m 10 -l 192.168.0.249 -p 11211

二、安装 memcache-client 和 cached_model , 执行下面的命令或到这里下载安装:

gem install cached_model –include-dependencies

三、配置 Rails App 使用 memcached Session Storage

1. 在 environments.rb 文件后加入以下代码:

require ‘memcache’
require ‘memcache_util’

# memcache defaults, environments may override these settings
unless defined? MEMCACHE_OPTIONS then
MEMCACHE_OPTIONS = {
:debug => false,
:namespace => ‘my_memcache’,
:readonly => false
}
end

# memcache configuration
unless defined? MEMCACHE_CONFIG then
File.open “#{RAILS_ROOT}/config/memcache.yml” do |memcache|
MEMCACHE_CONFIG = YAML::load memcache
end
end

# Connect to memcache
unless defined? CACHE then
CACHE = MemCache.new MEMCACHE_OPTIONS
CACHE.servers = MEMCACHE_CONFIG[RAILS_ENV]
end

# Configure the session manager to use memcache data store
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:database_manager => CGI::Session::MemCacheStore,
:cache => CACHE, :expires => 3600 * 12)

 

2.memcache.yml 文件内容:

production:
- 192.168.0.249:11211

development:
- 192.168.0.249:11211

benchmarking:
- 192.168.0.249:11211

四、使用lighttpd + mod_proxy + Mongrel  实现 Scale , 如果安装Mongrel请看我的前一篇Blog:使用Mongrel替代scgi .

1. 实现目标: http://mongrel.rubyforge.org/docs/lighttpd.html 

2.Lighttpd 配置 

server.modules = ( "mod_rewrite", "mod_redirect",
  “mod_access”, “mod_accesslog”, “mod_compress”,
  “mod_proxy”)

$HTTP[”url”] =~ “^/myapp1/” {
proxy.balance = “fair”

proxy.server = (”" => (
(”host”  => “127.0.0.1″,”port” => 4000),

(”host”  => “192.168.0.60″,”port” => 3000)
))
}

$HTTP[”url”] =~ “^/myapp2/” {
proxy.palance = “fair”

proxy.server = (”" => (
(”host” => “127.0.0.1″,”port” => 4001),

(”host”  => “192.168.0.60″,”port” => 3001)

))
}

 
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg

Tags:

No Responses

Leave a Response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>