到这里下载安装并启动(Debian 上我使用是memcached-1.1.13.tar.gz):
./memcached -d -u root -m 10 -l 192.168.0.249 -p 11211
2、安装 memcache-client 和 cached_model , 执行下面命令或到这里下载安装:
gem cached_model –-dependencies
3、配置 Rails App 使用 memcached Session Storage
1. 在 environments.rb 文件后加入以下代码:
require ‘memcache’
require ‘memcache_util’
# memcache defaults, environments may override these tings
unless d? MEMCACHE_OPTIONS then
MEMCACHE_OPTIONS = {
:debug => false,
: => ‘my_memcache’,
:readonly => false
}
end
# memcache configuration
unless d? MEMCACHE_CONFIG then
File.open “#{RAILS_ROOT}/config/memcache.yml” do |memcache|
MEMCACHE_CONFIG = YAML::load memcache
end
end
# Connect to memcache
unless d? CACHE then
CACHE = MemCache. 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
4、使用lighttpd + mod_proxy + Mongrel 实现 Scale , 如果安装Mongrel请看我前篇Blog:使用Mongrel替代scgi .
1. 实现目标: http://mongrel.rubyforge.org/docs/lighttpd.html
))
}
最新评论