redis-cli重定向到127.0.0.1

时间:2016-05-20 08:25:07

标签: redis redis-cluster redis-cli

我在PC1上启动了Redis群集,然后在PC2上连接它。当需要重定向到另一个群集节点时,它会显示Redirected to slot [7785] located at 127.0.0.1,但应显示Redirected to slot [7785] located at [IP of PC1, like 192.168.1.20],然后显示错误。怎么了?我该怎么办?

输出:

[admin@localhost ~]$ redis-cli -c -h 192.168.1.20 -p 30001
192.168.1.20:30001> get foo
-> Redirected to slot [12182] located at 127.0.0.1:30003
Could not connect to Redis at 127.0.0.1:30003: Connection refused
Could not connect to Redis at 127.0.0.1:30003: Connection refused
not connected>

redis-cli -h 192.168.1.20 -p 30001 cluster nodes的输出:

5f6d6f1319318233917aba92b6ab0e244b3260d7 127.0.0.1:30004 slave 4c7b046ecaeb2dc689cbad21ee3466fb43b48fb9 0 14639
84410573 4 connected
e04d5b461cb6a2b48cb2a607e2140b7c1d32af25 127.0.0.1:30006 slave 3fc25c3851f7a9afd09b60739434118c25cd9243 0 14639
84410473 6 connected
3fc25c3851f7a9afd09b60739434118c25cd9243 127.0.0.1:30003 master - 0 1463984410573 3 connected 10923-16383
4c7b046ecaeb2dc689cbad21ee3466fb43b48fb9 127.0.0.1:30001 myself,master - 0 0 1 connected 0-5460
7383830ac84f199db346da3112b5aaf9e124d3cf 127.0.0.1:30005 slave 1eeeb51522aed364fcf9623d6045fa3df2748579 0 14639
84410573 5 connected
1eeeb51522aed364fcf9623d6045fa3df2748579 127.0.0.1:30002 master - 0 1463984410473 2 connected 5461-10922

4 个答案:

答案 0 :(得分:2)

嘿,您可以尝试将redis群集实例绑定到服务器的IP

更新你的redis.conf以添加

  

绑定172.31.28.76

PS-根据需要更新IP

答案 1 :(得分:1)

这是因为您的所有Redis IP地址都已更新到127.0.0.1,并且他们认为其他Redis也位于127.0.0.1中。如果群集中的节点只是相互通信,那就没错了,但是当来自其他主机的连接想知道群集时,这肯定是不合适的。

在这种情况下,您的客户要求Redis提供一个不负责的密钥,Redis告诉客户重定向到127.0.0.1:30003。客户端误解了它并试图在其本地主机上连接端口30003,当然一无所获。

要解决此问题,请尝试将具有正确IP的cluster meet发送到群集中的每个Redis。我做了这样的实验

# initial, Redis doesn't know its IP before a meet
127.0.0.1:7000> cluster nodes
8af9e47cb96f3bd8fff3800c38da11601157605d :7000 myself,master - 0 0 0 connected

# meet from 127.0.0.1, and their IP addresses updated to 127.0.0.1
127.0.0.1:7000> cluster meet 127.0.0.1 7001
OK
127.0.0.1:7000> cluster nodes
8af9e47cb96f3bd8fff3800c38da11601157605d 127.0.0.1:7000 myself,master - 0 0 0 connected
2c3d9b6c29f21ecd846f42bcfb238099d88b57df 127.0.0.1:7001 master - 0 1463987186714 1 connected

# send another meet, use the eth0 IP other than lo
127.0.0.1:7000> cluster meet 172.31.28.76 7001
OK
127.0.0.1:7000> cluster nodes
8af9e47cb96f3bd8fff3800c38da11601157605d 127.0.0.1:7000 myself,master - 0 0 0 connected
2c3d9b6c29f21ecd846f42bcfb238099d88b57df 172.31.28.76:7001 master - 0 1463987192672 1 connected

# connect to :7001, its cluster nodes are what we expect
127.0.0.1:7001> cluster nodes
2c3d9b6c29f21ecd846f42bcfb238099d88b57df 172.31.28.76:7001 myself,master - 0 0 1 connected
8af9e47cb96f3bd8fff3800c38da11601157605d 172.31.28.76:7000 master - 0 1463987203631 0 connected
# send another meet to fix
127.0.0.1:7001> cluster meet 172.31.28.76 7000
OK

# back to :7000, its address updated
127.0.0.1:7000> cluster nodes
8af9e47cb96f3bd8fff3800c38da11601157605d 172.31.28.76:7000 myself,master - 0 0 0 connected
2c3d9b6c29f21ecd846f42bcfb238099d88b57df 172.31.28.76:7001 master - 0 1463987210539 1 connected

在您的情况下,您可以向每个Redis发送多个cluster meet命令,以确保其所有同行的IP更新。

答案 2 :(得分:0)

您说过,您正在PC1上运行Redis服务器。 然后提及PC1的IP地址(在您的情况下为192.168.1.20),同时提及redis节点配置文件中的绑定选项。

集群的节点配置文件示例-

bind 192.168.1.20  
port 6000  
cluster-enabled yes  
cluster-config-file "nodes.conf"  
cluster-node-timeout 5000
appendonly yes

答案 3 :(得分:0)

您必须使用-c选项 例如您要在端口6379

上使用客户端

$ service redis-server start

$ redis-cli -c -p 6379