Ruby on rails 轨道&x2B;Dalli memcache gem:Dallier错误:没有可用的服务器
嗨,我在服务器上设置Rails项目时遇到问题,因为apache一直在抱怨Ruby on rails 轨道&x2B;Dalli memcache gem:Dallier错误:没有可用的服务器,ruby-on-rails,memcached,dalli,Ruby On Rails,Memcached,Dalli,嗨,我在服务器上设置Rails项目时遇到问题,因为apache一直在抱怨 DalliError:没有可用的服务器 我在我的ubuntu机器上安装了memcached,但它仍然不能工作。我的rails项目在environments/production.rb中还有config.cache\u store=:dalli\u store,'localhost:11211',{:namespace=>“production”}。我如何调试这个 我的日志在每次请求之前显示: localhost:11211
DalliError:没有可用的服务器
我在我的ubuntu机器上安装了memcached
,但它仍然不能工作。我的rails项目在environments/production.rb中还有config.cache\u store=:dalli\u 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
我也有同样的问题。
首先,我将memcached安装为gem
gem安装memcached
并得到错误“DalliError:没有可用的服务器”
然后我安装了memcached
sudo apt get install memcached
。
它现在工作正常。这是因为有人将
/etc/hosts
文件更改为将127.0.1.1
指向本地主机,而不是127.0.0.1
。改变这一点后,memcached
起了作用。对于95%看到这个错误的人来说,公认的答案可能会解决这个问题,但我发现这个问题更为根本:
从服务器上,我无法ping 127.0.0.1
。这意味着Dalli
无法连接到默认运行在127.0.0.1:11211
上的memcache
服务器
可能导致此问题的原因有很多,但最有可能的是缺少网络接口。如果运行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
如果您是自制用户:
brew install memcached
检查服务是否正在运行:
brew services list
如果没有,请启动它:
brew services start memcached
使用
127.0.0.1
而不是localhost
可以解决您(和我)的问题
config.cache\u store=:dalli\u store,'127.0.0.1:11211',{namespace:'production'}
在我的例子中,我最近更新了服务器上的memcached,但Ruby守护进程在升级过程中一直在运行。只需重新启动Ruby守护进程,错误就消失了。(我还重新启动了mechached。)您正在运行什么来启动memcached?请确保该服务也已启用sudo systemctl enable memcached
(启动时启动)sudo systemctl start memcached
(立即启动)如果您不确定服务是否正在运行,请使用systemctl status memcached
解决同样的问题。如果Ruby将“localhost”解释为“::1”(IPv6地址),则会发生这种情况。见: