The Redis replication system is failing because a replica is unable to connect to and synchronize with multiple master instances simultaneously.
This typically happens when a replica is configured to point to more than one master, a setup that Redis doesn’t natively support for standard master-slave replication. The error message you’re seeing, often ERR Master is not a master or connection refused errors, indicates that the replica is trying to establish a replication connection with something that isn’t a valid master, or more commonly, that the replica is already in a replication state with one master and cannot initiate a second, independent one.
Here are the most common causes and their fixes:
-
Misconfiguration of
replicaoformasterofdirectives: The most frequent culprit is an incorrectreplicaof(ormasterofin older Redis versions) directive in the replica’s configuration file. A replica can only replicate from one master. If you have multiplereplicaoflines, or if you’re trying to set up a multi-master scenario using standard replication, it will fail.- Diagnosis: Check the
redis.conffile of the replica instance. Look forreplicaofdirectives. - Fix: Ensure there is only one
replicaof <masterip> <masterport>line. If you need to replicate from multiple masters, you’ll need to set up multiple replica instances, each pointing to a different master.# Example redis.conf snippet on the replica replicaof 192.168.1.100 6379 # NO other replicaof lines - Why it works: Redis’s replication protocol is inherently a one-to-one relationship from replica to master. The directive tells the replica which single source of truth to follow.
- Diagnosis: Check the
-
Replica is already replicating from another master: If the replica was previously configured to replicate from a different master, it needs to be explicitly told to stop before it can start replicating from a new one.
- Diagnosis: Connect to the replica instance using
redis-cliand runREPLICAINFO. This will show you if it’s currently replicating and from whom. - Fix: First, stop replication from the old master. Then, configure it for the new master.
redis-cli -p <replica_port> > REPLICAOF NO ONE > REPLICAOF <new_master_ip> <new_master_port> - Why it works:
REPLICAOF NO ONEbreaks the existing replication stream, allowing the instance to transition to a standalone state before establishing a new replication link.
- Diagnosis: Connect to the replica instance using
-
Network connectivity issues to all masters: If the replica cannot reach any of the masters it’s configured to replicate from, it will fail. This is especially relevant if you’ve specified multiple
replicaoflines (even though only one will be attempted at a time, the system might try to validate them or error out on the first invalid one).- Diagnosis: From the replica server, try to
pingortelnetto each master’s IP address and port.ping 192.168.1.100 telnet 192.168.1.100 6379 - Fix: Ensure firewalls (e.g.,
ufw,iptables, cloud security groups) are not blocking traffic on the Redis port (default 6379) between the replica and all masters. Verify network routes are correct. - Why it works: Redis replication relies on a stable TCP connection. If the connection cannot be established, the replication handshake fails.
- Diagnosis: From the replica server, try to
-
Authentication mismatch (if using
requirepass): If your master instances require a password for replication (masterauthdirective) and the replica is not configured with the correct password, the replication will fail with authentication errors.- Diagnosis: Check the
redis.confof the master forrequirepassand theredis.confof the replica formasterauth. - Fix: In the replica’s
redis.conf, add or correct themasterauthdirective to match the master’s password.# In replica's redis.conf masterauth <master_password> replicaof <master_ip> <master_port> - Why it works: Redis uses a password-based handshake during replication to authenticate the replica to the master.
- Diagnosis: Check the
-
Master is not actually a master (or is misconfigured): The error "Master is not a master" can sometimes be literal. The instance designated as a master might itself be configured as a replica, or it might have issues preventing it from accepting replication connections.
- Diagnosis: Connect to the intended master instance and run
INFO replication. It should showrole:master. If it showsrole:slave, it’s configured as a replica. - Fix: If the intended master is a replica, reconfigure it to be a master by removing its
replicaofdirective or setting it toNO ONE. If it’s a master but not accepting connections, check itsredis.confforprotected-mode yesand ensurebindis set appropriately, or that it’s not in a state where it’s refusing new connections.# On the intended master redis-cli > CONFIG SET protected-mode no > CONFIG SET bind 0.0.0.0 # Or specific interface IP > CONFIG REWRITE > INFO replication # Should show role:master - Why it works: Ensures the designated master is indeed functioning as a master and is accessible for replication.
- Diagnosis: Connect to the intended master instance and run
-
Redis version compatibility issues: While less common, very old versions of Redis might have subtle differences in replication handling. If you’re mixing very old and very new versions, or if you’ve upgraded masters but not replicas (or vice-versa) without proper planning, you could encounter issues.
- Diagnosis: Check the Redis versions on all involved instances using
redis-cli --versionorINFO server. - Fix: Upgrade all Redis instances to a recent, stable version. Prioritize upgrading masters before replicas, or ensure compatibility between versions if an immediate upgrade isn’t possible.
- Why it works: Ensures consistent behavior and bug fixes across the replication topology.
- Diagnosis: Check the Redis versions on all involved instances using
After resolving these, you might encounter a NOAUTH Authentication required error if your masters have requirepass set, but your replicas were not configured with masterauth.