一、安装 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 settingsunless defined? MEMCACHE_OPTIONS thenMEMCACHE_OPTIONS = {:debug => false,:namespace => ‘my_memcache’,:readonly => false}end
# memcache configurationunless defined? MEMCACHE_CONFIG thenFile.open “#{RAILS_ROOT}/config/memcache.yml” do |memcache|MEMCACHE_CONFIG = YAML::load memcacheendend
# Connect to memcacheunless defined? CACHE thenCACHE = MemCache.new MEMCACHE_OPTIONSCACHE.servers = MEMCACHE_CONFIG[RAILS_ENV]end
# Configure the session manager to use memcache data storeActionController::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
500)this.width=500'>
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)
))} |