【问题标题】:Redis cluster creating cannot connect to the server, what's wrong?Redis集群创建无法连接服务器,怎么回事?
【发布时间】:2016-09-10 12:23:09
【问题描述】:
我在阿里云上部署了 3 台不同的服务器,每台服务器运行 2 个 redis 实例,端口分别为 6379 和 6380。
我试图用这 6 个节点构建一个 redis 集群。(Redis 版本 3.2.0)。但它失败并说“对不起,无法连接到节点 10.161.94.215:6379”(10.161.94.215 是我的第一台服务器的局域网 IP 地址。)
虽然很明显服务器运行得很好,我可以通过 redis-cli 得到它。
Gem 已安装。
Requirepass 被禁止,不需要授权。
没有ip绑定
也没有保护模式。
error pic
关于集群的所有配置选项都设置好了。
这是怎么回事?
【问题讨论】:
标签:
linux
database
redis
redis-cluster
【解决方案1】:
我想我现在知道为什么了。
使用本地主机的IP。
src/redis-trib.rb create 127.0.0.1:6379 127.0.0.1:6380 h2:p1 h2:p2 h3:p1 h3:p2
【解决方案2】:
我认为您正在从不同的子网创建集群。那可能是个问题。
【解决方案3】:
看起来保护模式是 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
如果您尝试使用环回接口以外的其他东西连接到它,有关于如何更正此问题的说明:
拒绝 Redis 在保护模式下运行,因为启用了保护模式,没有指定绑定地址,也没有向客户端请求身份验证密码。在此模式下,仅接受来自环回接口的连接。如果您想从外部计算机连接到 Redis,您可以采用以下解决方案之一: 1) 只需禁用保护模式,通过从服务器的同一主机连接到 Redis 从环回接口发送命令 'CONFIG SET protected-mode no'正在运行,但是如果这样做,请确保 Redis 不能从 Internet 公开访问。使用 CONFIG REWRITE 使此更改永久生效。 2) 或者,您可以通过编辑 Redis 配置文件并将保护模式选项设置为“否”来禁用保护模式,然后重新启动服务器。 3) 如果您手动启动服务器只是为了测试,请使用“--protected-mode no”选项重新启动它。 4) 设置绑定地址或认证密码。注意:您只需执行上述操作之一,服务器即可开始接受来自外部的连接。
redis-trib.rb 的输出相当简洁(大概是这样)。
【解决方案4】:
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。