Rails,Passenger和Memcached:在初始化期间无法找到服务器

时间:2010-05-28 15:23:08

标签: ruby-on-rails memcached passenger

我希望有人可以帮我解决一个我确定是用户错误的问题。

以下配置详细信息适用于我的所有其他环境,包括集成,开发和qa。但是,生产服务器会出现以下错误:

<ActionController::Session::MemCacheStore:0x2b45f6acb248> unable to find server during initialization.

当我从有问题的服务器telnet到memcached框并运行'stats'时,我得到:

STAT pid 16136  
STAT uptime 7398638  
STAT time 1275059978    
STAT version 1.2.8    
STAT pointer_size 64  
STAT rusage_user 7.085922  
STAT rusage_system 13.275981  
STAT curr_items 10878  
STAT total_items 11441  
STAT bytes 2020180  
STAT curr_connections 5  
STAT total_connections 306  
STAT connection_structures 11  
STAT cmd_flush 0  
STAT cmd_get 457326  
STAT cmd_set 11441  
STAT get_hits 412184  
STAT get_misses 45142  
STAT evictions 0  
STAT bytes_read 22600329  
STAT bytes_written 53036649  
STAT limit_maxbytes 30064771072  
STAT threads 5  
STAT accepting_conns 1  
STAT listen_disabled_num 0

以下是配置详细信息和stacktrace。

config / environment.rb(重要部分):

config.action_controller.session_store = :mem_cache_store  
config.gem "memcache-client", :lib => 'memcache'  

配置/环境/ production.rb:

config.cache_store = :mem_cache_store

require 'memcache'  

# Caching  
# Memcached configuration  
memcache_options = {  
  :c_threshold => 100_000,  
  :compression => true,  
  :debug => false,  
  :namespace => 'gucci',  
  :readonly => false,  
  :urlencode => false,  
  :multithread => true  
}  

CACHE = MemCache.new memcache_options  
CACHE.servers = ['10.x.x.x:11211']  

堆栈跟踪:

/var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/session/mem_cache_store.rb    20      in `initialize'  
1   /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb   72  in `new'  
2   /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb   72  in `build'  
3   /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb   116     in `build'  
4   /var/www/oro/production/releases/20100528130253/vendor/rails/activesupport/lib/active_support/inflector.rb  361     in `inject'  
5   /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb   116     in `each'  
6   /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb   116     in `inject'  
7   /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/middleware_stack.rb   116     in `build'  
8   /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/dispatcher.rb     130     in `build_middleware_stack'  
9   /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/dispatcher.rb     81  in `initialize'  
10  /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/dispatcher.rb     51  in `new'  
11  /var/www/oro/production/releases/20100528130253/vendor/rails/actionpack/lib/action_controller/dispatcher.rb     51  in `run_prepare_callbacks'  
12  /var/www/oro/production/releases/20100528130253/vendor/rails/railties/lib/initializer.rb    631     in `prepare_dispatcher'  
13  /var/www/oro/production/releases/20100528130253/vendor/rails/railties/lib/initializer.rb    185     in `process'  
14  /var/www/oro/production/releases/20100528130253/vendor/rails/railties/lib/initializer.rb    113     in `send'  
15  /var/www/oro/production/releases/20100528130253/vendor/rails/railties/lib/initializer.rb    113     in `run'  
16  /var/www/oro/production/releases/20100528130253/config/environment.rb   29  
17  /usr/local//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb   31  in `gem_original_require'  
18  /usr/local//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb   31  in `require'
19  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/railz/application_spawner.rb   303     in `preload_application'  
20  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/railz/application_spawner.rb   252     in `initialize_server'  
21  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/utils.rb   255     in `report_app_init_status'  
22  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/railz/application_spawner.rb   237     in `initialize_server'  
23  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/abstract_server.rb     194     in `start_synchronously'  
24  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/abstract_server.rb     163     in `start'  
25  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/railz/application_spawner.rb   213     in `start'  
26  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/spawn_manager.rb   262     in `spawn_rails_application'  
27  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/abstract_server_collection.rb  126     in `lookup_or_add'  
28  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/spawn_manager.rb   256     in `spawn_rails_application'  
29  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/abstract_server_collection.rb  80  in `synchronize'  
30  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/abstract_server_collection.rb  79  in `synchronize'  
31  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/spawn_manager.rb   255     in `spawn_rails_application'  
32  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/spawn_manager.rb   154     in `spawn_application'  
33  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/spawn_manager.rb   287     in `handle_spawn_application'  
34  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/abstract_server.rb     352     in `__send__'  
35  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/abstract_server.rb     352     in `main_loop'  
36  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/lib/phusion_passenger/abstract_server.rb     196     in `start_synchronously'  
37  /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.10/bin/passenger-spawn-server   61

4 个答案:

答案 0 :(得分:2)

对我来说,事实证明,我的memcache守护进程没有收听127.0.0.1而是收听localhost。从init文件中删除-l localhost选项后,它工作得很好。 (默认是在所有设备上监听。)

答案 1 :(得分:1)

我在memcached gem中遇到了一些类似的问题,并切换到dali。达利的发展似乎更加活跃,而且速度要快得多。我按照github页面上的指示进行操作,并在大约十分钟内启动并运行。

答案 2 :(得分:0)

确定,但我没有看到您将会话配置设置为CACHE常量的位置:

config.action_controller.session = {
  :session_key => '_appname',
  :secret      => 'secret',
  :cache       => CACHE,
  :expires     => 10
}

这可能适用于qa / dev / testing,因为我认为默认情况下rails会在localhost上查找memcached存储。而在生产中,你似乎有一个不同的ip用于memcached服务器。

答案 3 :(得分:0)

在堆栈跟踪中有3行:

/var/www/oro/production/releases/20100528130253/config/environment.rb   29 
/usr/local//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb   31  in `gem_original_require'  
/usr/local//lib/ruby/site_ruby/1.8/rubygems/custom_require.rb   31  in `require'

似乎缺少某些宝石,请查看第29行的environment.rb

你试过吗?:

sudo gem install memcached

memcached正在运行吗?

sudo /etc/init.d/memcached start