Redis 集群创建副本绑定 Public IP
Redis Cluster Create Replicas Bind Public IP
我们在端口(8001、8002、8003、8004、8005、8006)中有 6 台 Redis 服务器 运行。
在每个 Redis 服务器的 redis.conf 上,我们以不同的方式绑定 ip,例如:
- 绑定 0.0.0.0
- 绑定私有 PUBLIC
- 绑定PUBLIC
如果我们访问正常的话:
redis-cli -h PUBLIC_IP -p 8001
但是当我们想要创建集群时,我们 运行:
./src/redis-cli --cluster create PUBLIC_IP:8001 PUBLIC_IP:8002 PUBLIC_IP:8003 PUBLIC_IP:8004 PUBLIC_IP:8005 PUBLIC_IP:8006 --cluster-replicas 1
控制台一直显示一直在等待集群永远:
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica PUBLIC_IP:8005 to PUBLIC_IP:8001
Adding replica PUBLIC_IP:8006 to PUBLIC_IP:8002
Adding replica PUBLIC_IP:8004 to PUBLIC_IP:8003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 7ab009459f7f5cf6cef5f46b691748dc236e4c26 PUBLIC_IP:8001
slots:[0-5460] (5461 slots) master
M: 0048ca2cd65c1315b8f0a7c952b69bfb494d5ace PUBLIC_IP:8002
slots:[5461-10922] (5462 slots) master
M: c6ee023719f200b0d175f428fa15e5ab767d0e04 PUBLIC_IP:8003
slots:[10923-16383] (5461 slots) master
S: cf636a1a46b1e947daec3e797cac524c613f08ca PUBLIC_IP:8004
replicates 7ab009459f7f5cf6cef5f46b691748dc236e4c26
S: 5d4bd1041457114353b0b30dbefd86ab8e4ae020 PUBLIC_IP:8005
replicates 0048ca2cd65c1315b8f0a7c952b69bfb494d5ace
S: 62f01289dc3f72cac4a1745fc77b7bd91ec5d107 PUBLIC_IP:8006
replicates c6ee023719f200b0d175f428fa15e5ab767d0e04
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
很多人说我们需要绑定私有 ip,但我们想在 public 上做,因为当我们连接到外部机器时,集群重定向到包含密钥的主机,如果我们绑定私有 ip,重定向将显示 "redirect to PRIVATE_IP" 并且不会按预期工作。
我们是否缺少让集群通过 public IP 加入的东西?
Redis is designed to be accessed by trusted clients inside trusted environments.
另请参阅:How to connect to redis from remote guide
当服务器绑定到其 public ip 时,它可以收到来自所有人的请求,因此除非您围绕它建立了一些安全措施,否则任何人都可以访问和操作您的数据。
在 redis 集群中,规则是相同的,绑定在 public ips 上的副本被公开。
redis 集群的默认用例是一台机器(或多台机器)从它的专用网络访问它,除非你知道你在做什么,否则你不应该转移注意力。
如果这对你的用例有意义,你应该让访问 redis 集群的机器成为集群专用网络的一部分。
如果我在你那里,我会做的是:
- 用私有ip和环回ip绑定所有服务器即
bind {{ private_ip }} 127.0.0.1
- 在每台服务器上启用 ufw(或其他任何防火墙工具)并执行(对于 ufw)
allow from {{ private_ip }} to any port {{ redis_port }}
或类似操作。
- 我的内部 DNS 将拥有所有服务器及其各自私有 IP 的条目。
- 瞧!安全地创建和访问 redis 集群,没有任何安全漏洞。
注意:如果您仍然想通过 public 网络访问它们,那么您可以使用 SNAT
做一些解决方法
警告:将 redis 服务器绑定到 0.0.0.0
或 public ip 可能会导致严重的漏洞问题,例如:
- https://www.exploit-db.com/exploits/47195
- https://medium.com/@knownsec404team/rce-exploits-of-redis-based-on-master-slave-replication-ef7a664ce1d0
PS:您也可以按照此 medium 教程进行操作。
我们在端口(8001、8002、8003、8004、8005、8006)中有 6 台 Redis 服务器 运行。 在每个 Redis 服务器的 redis.conf 上,我们以不同的方式绑定 ip,例如:
- 绑定 0.0.0.0
- 绑定私有 PUBLIC
- 绑定PUBLIC
如果我们访问正常的话:
redis-cli -h PUBLIC_IP -p 8001
但是当我们想要创建集群时,我们 运行:
./src/redis-cli --cluster create PUBLIC_IP:8001 PUBLIC_IP:8002 PUBLIC_IP:8003 PUBLIC_IP:8004 PUBLIC_IP:8005 PUBLIC_IP:8006 --cluster-replicas 1
控制台一直显示一直在等待集群永远:
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica PUBLIC_IP:8005 to PUBLIC_IP:8001
Adding replica PUBLIC_IP:8006 to PUBLIC_IP:8002
Adding replica PUBLIC_IP:8004 to PUBLIC_IP:8003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 7ab009459f7f5cf6cef5f46b691748dc236e4c26 PUBLIC_IP:8001
slots:[0-5460] (5461 slots) master
M: 0048ca2cd65c1315b8f0a7c952b69bfb494d5ace PUBLIC_IP:8002
slots:[5461-10922] (5462 slots) master
M: c6ee023719f200b0d175f428fa15e5ab767d0e04 PUBLIC_IP:8003
slots:[10923-16383] (5461 slots) master
S: cf636a1a46b1e947daec3e797cac524c613f08ca PUBLIC_IP:8004
replicates 7ab009459f7f5cf6cef5f46b691748dc236e4c26
S: 5d4bd1041457114353b0b30dbefd86ab8e4ae020 PUBLIC_IP:8005
replicates 0048ca2cd65c1315b8f0a7c952b69bfb494d5ace
S: 62f01289dc3f72cac4a1745fc77b7bd91ec5d107 PUBLIC_IP:8006
replicates c6ee023719f200b0d175f428fa15e5ab767d0e04
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
很多人说我们需要绑定私有 ip,但我们想在 public 上做,因为当我们连接到外部机器时,集群重定向到包含密钥的主机,如果我们绑定私有 ip,重定向将显示 "redirect to PRIVATE_IP" 并且不会按预期工作。
我们是否缺少让集群通过 public IP 加入的东西?
Redis is designed to be accessed by trusted clients inside trusted environments.
另请参阅:How to connect to redis from remote guide
当服务器绑定到其 public ip 时,它可以收到来自所有人的请求,因此除非您围绕它建立了一些安全措施,否则任何人都可以访问和操作您的数据。
在 redis 集群中,规则是相同的,绑定在 public ips 上的副本被公开。
redis 集群的默认用例是一台机器(或多台机器)从它的专用网络访问它,除非你知道你在做什么,否则你不应该转移注意力。
如果这对你的用例有意义,你应该让访问 redis 集群的机器成为集群专用网络的一部分。
如果我在你那里,我会做的是:
- 用私有ip和环回ip绑定所有服务器即
bind {{ private_ip }} 127.0.0.1
- 在每台服务器上启用 ufw(或其他任何防火墙工具)并执行(对于 ufw)
allow from {{ private_ip }} to any port {{ redis_port }}
或类似操作。 - 我的内部 DNS 将拥有所有服务器及其各自私有 IP 的条目。
- 瞧!安全地创建和访问 redis 集群,没有任何安全漏洞。
注意:如果您仍然想通过 public 网络访问它们,那么您可以使用 SNAT
做一些解决方法警告:将 redis 服务器绑定到 0.0.0.0
或 public ip 可能会导致严重的漏洞问题,例如:
- https://www.exploit-db.com/exploits/47195
- https://medium.com/@knownsec404team/rce-exploits-of-redis-based-on-master-slave-replication-ef7a664ce1d0
PS:您也可以按照此 medium 教程进行操作。