{{tag>db replication redis}} ====== redis replication setup ====== In order for replication to work, you need to have at least 3 instance on redis on different servers preferrably. 2 of those server have to have ... replicaof 6379 ... in their config files. The master must not have that line when starting. This setup also uses redis-sentinel for failover. Here's an example of sentinel config file port 26379 pidfile "/run/redis/redis-sentinel-dns.pid" dir "/var/lib/redis-sentinel-dns" logfile "/var/log/redis/sentinel-dns.log" sentinel monitor master-dns 10.0.0.1 6379 2 sentinel auth-user master-dns yourauthuser sentinel auth-pass master-dns passwored12345 sentinel down-after-milliseconds master-dns 5000 sentinel failover-timeout master-dns 10000 user default on nopass sanitize-payload ~* &* +@all The above must be the same on all sentinel instances. Example output from redis-sentinel which shows 2 replicas 127.0.0.1:26379> SENTINEL replicas master-dns 1) 1) "name" 2) "10.0.0.2:6379" 3) "ip" 4) "10.0.0.2" 5) "port" 6) "6379" 7) "runid" 8) "db734ef0bd69a043632efad123dff5a6f4292b64" 9) "flags" 10) "slave" 11) "link-pending-commands" 12) "0" 13) "link-refcount" 14) "1" 15) "last-ping-sent" 16) "0" 17) "last-ok-ping-reply" 18) "625" 19) "last-ping-reply" 20) "625" 21) "down-after-milliseconds" 22) "5000" 23) "info-refresh" 24) "3101" 25) "role-reported" 26) "slave" 27) "role-reported-time" 28) "13207" 29) "master-link-down-time" 30) "0" 31) "master-link-status" 32) "ok" 33) "master-host" 34) "10.0.0.1" 35) "master-port" 36) "6379" 37) "slave-priority" 38) "100" 39) "slave-repl-offset" 40) "6405" 41) "replica-announced" 42) "1" 2) 1) "name" 2) "10.0.0.3:6379" 3) "ip" 4) "10.0.0.3" 5) "port" 6) "6379" 7) "runid" 8) "a588edcbbd8f914000c341531da818617471c5a5" 9) "flags" 10) "slave" 11) "link-pending-commands" 12) "0" 13) "link-refcount" 14) "1" 15) "last-ping-sent" 16) "0" 17) "last-ok-ping-reply" 18) "251" 19) "last-ping-reply" 20) "251" 21) "down-after-milliseconds" 22) "5000" 23) "info-refresh" 24) "2973" 25) "role-reported" 26) "slave" 27) "role-reported-time" 28) "13208" 29) "master-link-down-time" 30) "0" 31) "master-link-status" 32) "ok" 33) "master-host" 34) "10.0.0.1" 35) "master-port" 36) "6379" 37) "slave-priority" 38) "100" 39) "slave-repl-offset" 40) "6419" 41) "replica-announced" 42) "1" 127.0.0.1:26379> In above case the master is at IP 10.0.0.1 as shown: 127.0.0.1:26379> SENTINEL master master-dns 1) "name" 2) "master-dns" 3) "ip" 4) "10.0.0.1" 5) "port" 6) "6379" 7) "runid" 8) "fef19e25fd8fed69b64f9733fe276889455171ce" 9) "flags" 10) "master" 11) "link-pending-commands" 12) "0" 13) "link-refcount" 14) "1" 15) "last-ping-sent" 16) "0" 17) "last-ok-ping-reply" 18) "170" 19) "last-ping-reply" 20) "170" 21) "down-after-milliseconds" 22) "5000" 23) "info-refresh" 24) "6640" 25) "role-reported" 26) "master" 27) "role-reported-time" 28) "414310" 29) "config-epoch" 30) "0" 31) "num-slaves" 32) "2" 33) "num-other-sentinels" 34) "2" 35) "quorum" 36) "2" 37) "failover-timeout" 38) "10000" 39) "parallel-syncs" 40) "1" 127.0.0.1:26379> ====== Tested on ====== * redis 6.2.17 * AlmaLinux release 9.5 (Teal Serval) ====== See also ====== ====== References ====== * https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#a-quick-tutorial * https://redis.io/learn/howtos/quick-start/cheat-sheet