Rails + Dalli memcache gem:DalliError:没有可用的服务器

时间:2013-08-28 20:22:50

标签: ruby-on-rails memcached dalli

嗨,我在服务器上设置Rails项目时遇到了麻烦,因为apache一直在抱怨

DalliError: No server available

我在我的ubuntu机器上安装了memcached,但它仍然无效。我的rails项目在environment / production.rb中也有config.cache_store = :dalli_store, 'localhost:11211', { :namespace => "production" }。我该如何调试呢?

我的日志显示在每个请求之前:

localhost:11211 failed (count: 6)
DalliError: No server available

telnet到11211:

    root@s2:/usr/local/www/production/current/log# telnet localhost 11211
    Trying 127.0.1.1...
    telnet: Unable to connect to remote host: Connection refused

6 个答案:

答案 0 :(得分:26)

我遇到了同样的问题。 首先我将memcached安装为gem gem install memcached 并得到错误“DalliError:没有服务器可用”

然后我做了安装memcached sudo apt-get install memcached。 现在工作正常。

答案 1 :(得分:8)

如果您是Homebrew用户:

brew install memcached

检查服务是否正在运行:

brew services list

如果没有,请启动它:

brew services start memcached

答案 2 :(得分:3)

这是因为有人将/etc/hosts文件更改为指向127.0.1.1而不是127.0.0.1。更改后,memcached工作。

答案 3 :(得分:0)

接受的答案可能会解决95%的人看到此错误的问题,但就我而言,我发现问题更为根本:

从服务器,我无法ping 127.0.0.1。这意味着Dalli无法连接到memcache服务器,默认情况下会在127.0.0.1:11211上运行。

可能导致此问题,但最有可能只是缺少网络接口。如果您运行ifconfig应该在输出中看到类似的内容:

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:15686 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15686 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:23730314 (23.7 MB)  TX bytes:23730314 (23.7 MB)

如果缺少此项,请确保您的/etc/network/interfaces文件包含以下本地接口定义:

auto lo
iface lo inet loopback

然后重新启动网络服务:

sudo /etc/init.d/networking restart

答案 4 :(得分:0)

使用127.0.0.1代替localhost应该可以解决您(和我的)问题。

config.cache_store = :dalli_store, '127.0.0.1:11211', { namespace: 'production' }

答案 5 :(得分:0)

就我而言,我最近更新了服务器上的memcached,但是Ruby守护程序一直在升级过程中运行。只需重新启动Ruby守护程序,错误就消失了。 (我也重新启动了。)

相关问题