Ruby-on-rails Rails + Dalli memcache gem:DalliError:没有可用的服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18497502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:37:17  来源:igfitidea点击:

Rails + Dalli memcache gem: DalliError: No server available

ruby-on-railsmemcacheddalli

提问by bigpotato

Hi I'm having trouble setting up my Rails project on my server because apache keeps complaining

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

DalliError: No server available.

DalliError: No server available.

I installed memcachedon my ubuntu machine, but it still doesn't work. My rails project also has config.cache_store = :dalli_store, 'localhost:11211', { :namespace => "production" }in environments/production.rb. How would I debug this?

memcached在我的 ubuntu 机器上安装了,但它仍然不起作用。我的 rails 项目也在config.cache_store = :dalli_store, 'localhost:11211', { :namespace => "production" }environment/production.rb 中。我将如何调试这个?

My log shows before each request:

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

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

telnet to 11211:

远程登录到 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

回答by Sagar Arlekar

I had the same problem. First I installed memcached as a gem gem install memcachedand got the error "DalliError: No server available"

我有同样的问题。首先,我将 memcached 安装为 gem gem install memcached并收到错误“DalliError: No server available”

Then I installed memcached by doing sudo apt-get install memcached. It works fine now.

然后我通过执行 sudo apt-get install memcached. 它现在工作正常。

回答by Bryan Ash

If you're a Homebrew user:

如果您是 Homebrew 用户:

brew install memcached

Check if the service is running:

检查服务是否正在运行:

brew services list

If not, start it:

如果没有,请启动它:

brew services start memcached

回答by bigpotato

It was because someone changed the /etc/hostsfile to point 127.0.1.1to localhost instead of 127.0.0.1. After changing that, memcachedworked.

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

回答by Tom Lord

The accepted answer will probably solve the issue for 95% of people who are seeing this error, but in my case I found the issue to be far more fundamental:

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

From the server, I was unable to ping 127.0.0.1. This meant Dallicould not connect to the memcacheserver, which by default runs on 127.0.0.1:11211.

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

There are a number of things that couldcause this issue, but the most likely is simply a missing network interface. If you run ifconfig, you shouldsee something like this in the output:

有许多的东西,可能会导致此问题,但最有可能的是一个简单的失踪网络接口。如果您运行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)

If this is missing, ensure your /etc/network/interfacesfile contains the following local interface definition:

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

auto lo
iface lo inet loopback

And then restart the networking service:

然后重启网络服务:

sudo /etc/init.d/networking restart

回答by В?тал?й Адамков

Use 127.0.0.1instead of localhostshould solve your (and mine) issue.

使用127.0.0.1而不是localhost应该解决您(和我的)问题。

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

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

回答by Pistos

In my case, I had recently updated memcached on the server, but the Ruby daemon had kept running through the upgrade. After simply restarting the Ruby daemon, the errors went away. (I also restarted mechached.)

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