Getting a connection error when using redis-trib.r

2019-04-16 18:23发布

问题:

I have all my Redis servers configured like this:

Masters: 192.168.0.106:7001, 192.168.0.105.7001, 192.168.0.112:7001

Slaves: 192.168.0.106:7002, 192.168.0.105:7002, 192.168.0.122:7002

Where the 192.168.0.106:7002 server is a slave of the 192.168.0.106:7001 server and so on. I have all servers up ana running and can do redis-cli to all of them. I can see the 17001 and 17002 ports open too. But when I run:

./redis-trib.rb create --replicas 1 192.168.0.106:7001 192.168.0.105:7001 192.168.0.112:7001 192.168.0.106:7002 192.168.0.105:7002 192.1268.0.112:7002

I get an error:

Creating cluster

[ERR] Sorry, can't connect to node 192.168.0.106:7001

I have no idea how to troubleshoot this when all servers are working and their ports are open?

One thing is that I do have the masters protected with a password. Maybe redis-trib.rb is not able to handle servers which are password protected?

回答1:

redis-trib.rb cannot handle Redis nodes which are password-protected.

So trying to use it on such nodes would result in [ERR] Sorry, can't connect to node.

Why the redis-trib.rb utility does not handle authenticated nodes?

It has to do with the fact that when a Redis node is password protected only the communication on its main port (by default 6379) is protected. The communication on its cluster bus (Default Port + 10000 = 16379), where nodes in a cluster communicated with each other is not protected. So a Redis cluster is not really password-protected when individual nodes are. So having a password on individual Redis nodes in a Redis cluster adds little security value. Therefore the redis-trib.rb utility has not implemented any authentication.

More information here:

https://groups.google.com/forum/#!topic/redis-db/Z8lMxTfDct8



回答2:

I was getting the same problem.

But checking the redis.conf of my instance I saw that the bind option was commented out and by default Redis starts the process with *:port.

So I added this to redis.conf and now it works perfectly:

bind 0.0.0.0

If this a security error, you may need to add a password or specify the correct IP ranges.



回答3:

When you use external ip's, instead of 127.0.0.1. You have to add a new line into redis.conf: "protected-mode no"

At the tutorial "https://redis.io/topics/cluster-tutorial", you will see that you have to create one redis.conf, in each one of the folders: 7000, 7001, ..., 7005

The tutorial suggests:

port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

You just have to add a new line:

port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
protected-mode no

Remember to guarantee your security inside the firewall of machine.