<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Caiwangqin's blog

Focus on Life, Cloud Service, Smart Hardware, Architecture, Technic and beyond…

RubyonRails memcached Session Storage 实践

2006年9月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)

))
}



 

标签:

posted by Caiwangqin, 04:54

0 Comments:

发表评论

订阅 博文评论 [Atom]

<< 主页