Connecting to Cluster not working in Private Network
I have two VPS in same Private Network
Service running on 10.0.0.1 Redis Server running on 10.0.0.3 (bind 0.0.0.0 in redis.conf)
- Try connect using createClient to one Master then connect to be successful
- Try connect using Redis Insight use SSH Tunnel or direct with firewall disabled then connect to be successful
- Try connect using createCluster to one Master or three Master or all Master and Slave then return error
Redis Client Error ECONNREFUSED: Failed to connect errno: 24 syscall: "connect"
Tested on two version 4.6.15 and 4.7.0
This issue has been automatically marked as stale due to inactivity. It will be closed in 30 days if no further activity occurs. If you believe this issue is still relevant, please add a comment to keep it open.
Hello, thanks for the detailed report.
The behavior you're describing—createClient (standalone) works, but createCluster fails with ECONNREFUSED—is a classic symptom of a Redis Cluster topology misconfiguration in virtualized environments like VPSs or cloud setups (GCP, AWS).
The Node.js client (createCluster) is receiving an unreachable IP from the Redis server during cluster handshake.
1. The Root Cause: Advertised IP
When you connect a cluster client, the first node you connect to (the seed node, 10.0.0.3) responds with the entire cluster map, including the IP addresses for all other nodes.
If Redis is not explicitly told which IP to advertise, it defaults to an internal, non-routable IP (like 127.0.0.1) or a public IP that isn't accessible via the private network.
The client receives this wrong IP, tries to connect to it (the second connection attempt), and gets the ECONNREFUSED error.
2. The Solution: Use cluster-announce-ip
The fix is to explicitly configure every Redis Cluster node to advertise its correct private network IP address.
This setting must be added to the redis.conf file (or passed via command line flags) for every single master and replica in the cluster.
Step 1: Configure All Redis Nodes
On the server running the Redis nodes (e.g., 10.0.0.3), edit the configuration for each instance (e.g., ports 6379, 6380, 6381).
Find the configuration file and add/update the following directives:
# 1. Ensure the port is open and cluster mode is on
cluster-enabled yes
# 2. CRITICAL FIX: Force the node to advertise its correct private IP.
# If this is node 10.0.0.3, set it to 10.0.0.3.
# If you have nodes on 10.0.0.4, set that node to 10.0.0.4.
cluster-announce-ip 10.0.0.3
cluster-announce-port 6379
cluster-bus-port 16379
Step 2: Clean Up and Restart
Since the cluster stores old IP information, you must clean it up:
- Stop all Redis instances.
- Delete the Cluster Configuration File: Delete the
nodes.conffile for every instance. This forces the cluster to rebuild its topology with the new advertised IP.rm /path/to/redis/nodes.conf - Start all Redis instances.
- Recreate the Cluster: Run the cluster creation command again, using only the private IPs:
redis-cli --cluster create 10.0.0.3:6379 10.0.0.3:6380 10.0.0.3:6381 --cluster-replicas 0 --cluster-yes
3. Verification Check
Before re-running your Node.js code, verify that Redis is advertising the correct IPs.
From your service VPS (10.0.0.1), use redis-cli to check the node list:
redis-cli -c -h 10.0.0.3 -p 6379 cluster nodes
Expected Output: All nodes should now list their addresses as the private IPs (10.0.0.3, 10.0.0.4, etc.), not 127.0.0.1 or a public IP. Once this is correct, your createCluster client should connect without the ECONNREFUSED error.
Let us know if you still encounter issues after applying this configuration fix!