【问题标题】:Rescue : Connection refused - Unable to connect to Redis on localhost:6379救援:连接被拒绝 - 无法连接到 localhost:6379 上的 Redis
【发布时间】:2011-06-07 21:20:58
【问题描述】:

我已按照说明安装 resque,但现在当我尝试使用此命令生成工作人员时出现连接错误:

$ QUEUE=mailer rake environment resque:work --trace

这是我得到的错误:

连接被拒绝 - 无法连接到 localhost:6379 上的 Redis

【问题讨论】:

  • redis 服务器好像没有运行
  • Server Fault 有一个关于 Connection Refused 的规范问题。

标签: redis resque


【解决方案1】:

您是否验证过 redis-server 正在运行?请不要让我剖析以下命令,但您可以在终端中键入:

ps aux | grep redis

然后您应该会看到类似的内容:

redis 13319 0.0 0.0 2884 1056 ? Ss 10:54 0:00 /usr/bin/redis-server /etc/redis/redis.conf

如果它没有运行,我建议发出以下命令:

nohup redis-server &

这将启动一个 redis-server 进程并将其与终端分离。否则,我认为您需要在希望 redis-server 运行的整个过程中保持该终端打开。

(启动后验证进程是否正在运行总是一个好主意,因此请再次使用第一个命令。)

更新:我不确定这是否适用于所有版本,但在 Ubuntu 16.04 上的 Redis Server 3.0.6 上,您也可以发出 sudo service redis-server status。你会收到一些详细的输出,所以我不会全部发布,但这可能是我们中一些人的另一种选择。

【讨论】:

    【解决方案2】:

    你安装了redis吗?

    在 Ubuntu 上安装 REDIS

    参考:http://redis.io/download

    1. 下载、提取和编译 Redis 使用:-

      $ cd ~/Installations
      $ curl -O http://redis.googlecode.com/files/redis-2.2.1.tar.gz
      $ tar xzf redis-2.2.1.tar.gz
      $ cd redis-2.2.1
      $ sudo make
      
    2. 安装 Tcl(工具命令语言)运行时

      $ sudo apt-get install tcl8.5
      
    3. 运行 Redis 服务器

      $ src/redis-server
      [31371] 24 Feb 10:14:03 # Warning: no config file specified, using the default config. In order to   specify a config file use 'redis-server /path/to/redis.conf'
      [31371] 24 Feb 10:14:03 * Server started, Redis version 2.2.1
      [31371] 24 Feb 10:14:03 # WARNING overcommit_memory is set to 0! Background save may  fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
      [31371] 24 Feb 10:14:03 * The server is now ready to accept connections on port 6379
      

    【讨论】:

      【解决方案3】:

      去做吧:- sudo apt-get install redis-server

      【讨论】:

        【解决方案4】:

        使用redis-server 启动服务器,然后使用redis-cli ping 测试服务器是否启动。如果服务器启动,您应该会收到一个 pong。这是直接从文档中获取的。 enter link description here

        【讨论】:

          【解决方案5】:

          你应该使用“127.0.0.1:6379”而不是“localhost:6379”来连接redis。 所以,无论你想在哪里连接redis,都使用redis-server ip。

          【讨论】:

          • 好像redis端口和HTTP端口没有关系。 127.0.0.1 是 HTTP 本地主机。