8

我在 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

4 回答 4

3

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

更新你的 redis.conf 以添加

绑定 172.31.28.76

PS- 根据需要更新 IP

于 2018-06-01T06:18:09.503 回答
2

那是因为你所有的 Redis IP 地址都更新为 127.0.0.1,而且他们认为其他 Redis 也位于 127.0.0.1。如果集群中的节点只是相互通信,那并没有错,但当来自其他主机的连接想要了解集群时,这绝对是不正确的。

在这种情况下,您的客户端向 Redis 请求它不负责的密钥,Redis 告诉客户端重定向到 127.0.0.1:30003。客户端误会了,尝试在它的localhost中连接30003端口,当然一无所获。

要修复它,请尝试cluster meet使用正确的 IP 向集群中的每个 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 在其所有对等方处更新。

于 2016-05-23T07:26:47.007 回答
0

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

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

bind 192.168.1.20  
port 6000  
cluster-enabled yes  
cluster-config-file "nodes.conf"  
cluster-node-timeout 5000
appendonly yes
于 2020-02-09T13:18:34.980 回答
0

你必须使用-c选项,例如你想在端口上使用客户端6379

$ service redis-server start

$ redis-cli -c -p 6379

于 2020-03-07T12:17:23.633 回答