Redis集群创建无法连接到服务器,有什么不对?

时间:2016-05-14 08:54:41

标签: linux database redis redis-cluster

我在Aliyun上部署了3台不同的服务器,每台服务器运行2个redis实例,端口号为6379和6380.

我正在尝试使用这6个节点构建一个redis集群。(Redis版本3.2.0)。但它失败并说"抱歉,无法连接到节点10.161.94.215:6379" (10.161.94.215是我的第一台服务器的lan ip地址。)

显然服务器运行得很好,我可以通过redis-cli获得它。

安装了Gem。

禁止使用Requirepass,不需要auth。

没有ip bind

也没有保护模式。

error pic

有关群集的所有配置选项都设置良好。

这有什么问题?

4 个答案:

答案 0 :(得分:0)

我想我现在知道为什么。

使用本地主机的IP。

src/redis-trib.rb create 127.0.0.1:6379 127.0.0.1:6380 h2:p1 h2:p2 h3:p1 h3:p2

答案 1 :(得分:0)

我认为您是从不同的子网创建群集。那可能是个问题。

答案 2 :(得分:0)

看起来保护模式是redis 3.2中的新安全功能。简短版本是如果您没有明确绑定到IP地址,它只允许访问localhost。

如果您只想在单个主机上创建群集,这可能没问题。如果您使用多台主机创建群集,则需要关闭保护模式或明确绑定到IP地址。

来自redis.conf文件:

# Protected mode is a layer of security protection, in order to avoid    that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.

# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes

如果您尝试使用环回接口之外的其他内容连接到它,有关于如何纠正此问题的说明:

  

DENIED Redis正在保护模式下运行,因为启用了保护模式,未指定绑定地址,也没有向客户端请求身份验证密码。在此模式下,仅从环回接口接受连接。如果要从外部计算机连接到Redis,可以采用以下解决方案之一:1)只需禁用保护模式发送命令' CONFIG SET保护模式否'通过从服务器运行的同一主机连接到Redis,从环回接口,但是如果您这样做,则无法从Internet公开访问MAKE SURE Redis。使用CONFIG REWRITE使此更改成为永久更改。 2)或者,您可以通过编辑Redis配置文件,并将保护模式选项设置为“不”,然后重新启动服务器来禁用保护模式。 3)如果您手动启动服务器进行测试,请使用' - protected-mode no'重新启动它。选项。 4)设置绑定地址或验证密码。注意:您只需要执行上述操作之一,服务器就可以开始接受来自外部的连接。

redis-trib.rb的输出相当简洁(可能是恰当的)。

答案 3 :(得分:0)

sudo nano /etc/redis/6379.conf

Replace #bind 127.0.0.1 or bind 127.0.0.1 with bind 0.0.0.0   

sudo service redis_6379 restart

允许在任何地方访问redis。

相关问题