Rails 应用程序抱怨无法连接到 memcached,但我很确定它正在运行

Rails 应用程序抱怨无法连接到 memcached,但我很确定它正在运行

一切顺利,然后我重新启动了服务器。

现在:

$ ps aux | grep memcache
1000     27168  0.0  0.0 121972  1056 pts/0    Sl   15:18   0:00 memcached -m 64 -p 11211 -u nobody -l 127.0.0.1
1000     27816  0.0  0.0   7628   956 pts/0    S+   15:36   0:00 grep memcache

同时,rails 应用程序的日志中出现大量此类信息:

MemCacheError (No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:55 -0600 2011)): No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:55 -0600 2011)
MemCacheError (No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:55 -0600 2011)): No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:55 -0600 2011)
MemCacheError (No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:55 -0600 2011)): No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:55 -0600 2011)
MemCacheError (No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:55 -0600 2011)): No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:55 -0600 2011)
MemCacheError (No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:56 -0600 2011)): No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:56 -0600 2011)
MemCacheError (No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:56 -0600 2011)): No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:56 -0600 2011)
MemCacheError (No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:56 -0600 2011)): No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:56 -0600 2011)
MemCacheError (No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:56 -0600 2011)): No connection to server (localhost:11211 DEAD (Timeout::Error: execution expired), will retry at Tue Feb 15 15:35:56 -0600 2011)

因为我更像是一名开发人员,而不是一名服务器人员,而且我们实际上并不一个“服务器人员”,并且这正在生产中......我该从哪里开始呢?

答案1

netstat -tupln | grep -i memcache

这将告诉您您的 memcache 实例是否正在监听以及监听哪个端口。我会在 /etc/hosts 中检查 localhost 是否已定义。默认情况下应该是这样,但如果有人在 Vi 中对 DD 感到满意,您可能会遇到真正的问题。您的 PS 输出显示 memcache 以 -l 127.0.0.1 开头,但您的脚本正在连接到“localhost” - 从定义上讲,这是同一件事,但是,它是任意的,因为您可以删除 localhost 行,或者重新别名为 eth0 上的 IP。

memcache 是一个纯文本协议,因此请尝试 telnet 到该端口

telnet 127.0.0.1 11211

你应该得到同样的回应

telnet localhost 11211

答案2

我们遇到了这个问题,更换 memcache 客户端后问题就解决了

https://github.com/mperham/dalli

(改变起来并不需要太多工作)

相关内容