我想在 Rails 中使用 memcached。
所以我在本地设置。好的。并部署到我的服务器..出现问题
问题是dalli无法加载到active_support/cache/mem_cache_store.rb..
我的服务器环境:ubuntu / nginx / unicorn / Rails 4 / capistrano 2
unicorn.log (编辑(添加更多日志))
E, [2014-08-09T10:46:52.306478 #3576] ERROR -- : reaped #<Process::Status: pid 25225 exit 1> worker=1
I, [2014-08-09T10:46:52.306772 #3576] INFO -- : worker=1 spawning...
I, [2014-08-09T10:46:52.315784 #25228] INFO -- : worker=1 spawned pid=25228
I, [2014-08-09T10:46:52.316264 #25228] INFO -- : Refreshing Gem list
You don't have dalli installed in your application. Please add it to your Gemfile and run bundle install
E, [2014-08-09T10:46:52.377766 #25221] ERROR -- : Could not find cache store adapter for mem_cache_store (cannot load such file -- dalli) (RuntimeError)
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.4/lib/active_support/cache.rb:105:in `rescue in retrieve_store_class'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.4/lib/active_support/cache.rb:103:in `retrieve_store_class'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.4/lib/active_support/cache.rb:59:in `lookup_store'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/application/bootstrap.rb:62:in `block in <module:Bootstrap>'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/local/rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
/usr/local/rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
/usr/local/rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
/usr/local/rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
/usr/local/rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/tsort.rb:180:in `each'
/usr/local/rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
/usr/local/rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
/bps_data/apps/chimiseng/releases/20140809040739/config/environment.rb:5:in `<top (required)>'
config.ru:4:in `require'
config.ru:4:in `block in <main>'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn.rb:48:in `eval'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn.rb:48:in `block in builder'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:764:in `call'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:764:in `build_app!'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:628:in `init_worker_process'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:651:in `worker_loop'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:536:in `maintain_worker_count'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:294:in `join'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/bin/unicorn:23:in `load'
/bps_data/apps/chimiseng/shared/bundle/ruby/2.0.0/bin/unicorn:23:in `<main>'
@@@@编辑 START@@@@
添加有关此的信息..
在/path/to/shared/bundle/gems/activesupport-4.1.4/lib/activesupport/cache.rb:103-105
102 def retrieve_store_class(store)
103 require "active_support/cache/#{store}"
104 rescue LoadError => e
105 raise "Could not find cache store adapter for #{store} (#{e})"
106 else
107 ActiveSupport::Cache.const_get(store.to_s.camelize)
108 end
在 active_support/cache/mem_cache_store.rb 中需要
1 begin
2 require 'dalli' # <- error !!
3 rescue LoadError => e
4 $stderr.puts "You don't have dalli installed in your application. Please add it to your Gemfile and run bundle install"
5 raise e
6 end
@@@@@编辑END@@@@@
这是config/environment/production.rb 和 Gemfile
宝石文件
source 'https://rubygems.org'
...
# Use unicorn as the app server
gem 'unicorn'
gem 'dalli'
gem 'capistrano', "~> 2.15.0"
gem 'net-ssh', '~> 2.7.0'
gem 'rb-readline'
...
配置/环境/production.rb
...
config.cache_classes = true
config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store
...
APP_DIR 处的命令“bundle show”(存在 .bundle 文件夹)
...
* dalli (2.7.2)
...
和 ls /path/to/shared/bundle/ruby/2.0.0/gems
...
dalli-2.7.2
...
当然,APP_DIR/.bundle/config 是默认的。
---
BUNDLE_FROZEN: '1'
BUNDLE_PATH: /path/to/shared/bundle
BUNDLE_WITHOUT: development:test
BUNDLE_DISABLE_SHARED_GEMS: '1'
和/etc/memcached.conf
-d
logfile /path/to/shared/log/memcached.log
-m 64
-p 11211
-u memcache
-l 127.0.0.1
在我的服务器上,在 APP_DIR 命令“rails c -e production”中
Loading production environment (Rails 4.1.4)
irb(main):001:0> Rails.cache.stats
Dalli::Server#connect localhost:11211
localhost:11211 failed (count: 0) Errno::ECONNREFUSED: Connection refused - send
=> {"localhost:11211"=>nil}
irb(main):002:0>
irb(main):003:0* dc = Dalli::Client.new
=> #<Dalli::Client:0x007fa410d27d58 @servers=["127.0.0.1:11211"], @options={}, @ring=nil>
irb(main):004:0>
irb(main):005:0* dc.stats
.......
irb(main):006:0> y _
---
127.0.0.1:11211:
pid: '6657'
uptime: '476'
time: '1407552100'
version: 1.4.13
libevent: 2.0.16-stable
pointer_size: '64'
rusage_user: '0.000000'
rusage_system: '0.032002'
curr_connections: '5'
total_connections: '7'
connection_structures: '6'
reserved_fds: '20'
cmd_get: '0'
cmd_set: '1'
cmd_flush: '0'
cmd_touch: '0'
get_hits: '0'
get_misses: '0'
delete_misses: '0'
delete_hits: '0'
incr_misses: '0'
incr_hits: '0'
decr_misses: '0'
decr_hits: '0'
cas_misses: '0'
cas_hits: '0'
cas_badval: '0'
touch_hits: '0'
touch_misses: '0'
auth_cmds: '0'
auth_errors: '0'
bytes_read: '160'
bytes_written: '3709'
limit_maxbytes: '67108864'
accepting_conns: '1'
listen_disabled_num: '0'
threads: '4'
conn_yields: '0'
hash_power_level: '16'
hash_bytes: '524288'
hash_is_expanding: '0'
expired_unfetched: '0'
evicted_unfetched: '0'
bytes: '73'
curr_items: '1'
total_items: '1'
evictions: '0'
reclaimed: '0'
=> nil
irb(main):007:0>
和ps辅助| grep memcached 在我的服务器中
memcache 6657 0.0 0.2 324248 2228 ? Sl 11:33 0:00 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1
和/etc/init.d/unicorn_myapp 重启
reloaded OK
但是..服务器rails应用程序不起作用..
@@@编辑开始(添加信息)@@@
在我的服务器中,rails c -e production..
Loading production environment (Rails 4.1.4)
irb(main):001:0>require 'dalli'
=> false
irb(main):002:0>
这意味着.. dali 已经是必需的。不是吗?
嗯.. 为什么在 active_support/cache/mem_cache_store.rb 中不需要
@@@编辑结束@@@
但它在我当地的 ubuntu 上运行得很好!本地捆绑安装列表是同一台服务器(除了 gem spring)..
Loading production environment (Rails 4.1.4)
irb(main):001:0> Rails.cache.stats
Dalli::Server#connect localhost:11211
=> {"localhost:11211"=>{"pid"=>"1976", "uptime"=>"13302", "time"=>"1407552926", "version"=>"1.4.13", "libevent"=>"2.0.16-stable", "pointer_size"=>"64", "rusage_user"=>"0.724000", "rusage_system"=>"0.296000", "curr_connections"=>"5", "total_connections"=>"10", "connection_structures"=>"7", "reserved_fds"=>"20", "cmd_get"=>"0", "cmd_set"=>"0", "cmd_flush"=>"1", "cmd_touch"=>"0", "get_hits"=>"0", "get_misses"=>"0", "delete_misses"=>"0", "delete_hits"=>"0", "incr_misses"=>"0", "incr_hits"=>"0", "decr_misses"=>"0", "decr_hits"=>"0", "cas_misses"=>"0", "cas_hits"=>"0", "cas_badval"=>"0", "touch_hits"=>"0", "touch_misses"=>"0", "auth_cmds"=>"0", "auth_errors"=>"0", "bytes_read"=>"244", "bytes_written"=>"5617", "limit_maxbytes"=>"67108864", "accepting_conns"=>"1", "listen_disabled_num"=>"0", "threads"=>"4", "conn_yields"=>"0", "hash_power_level"=>"16", "hash_bytes"=>"524288", "hash_is_expanding"=>"0", "expired_unfetched"=>"0", "evicted_unfetched"=>"0", "bytes"=>"0", "curr_items"=>"0", "total_items"=>"0", "evictions"=>"0", "reclaimed"=>"0"}}
有什么问题??请帮帮我T^T因为这个我疯了..
无论如何..感谢您的阅读!