By synchronizing Redis, we can have a Slave with the Master’s data synchronized in real-time. This way, if the Master fails, we can point to the Slave and keep working. Additionally, if we have a lot of traffic, we can balance the readings between the two servers.
We compile and install Redis:
emerge -av dev-db/redis
rc-update add redis default
/etc/init.d/redis start
rc-update add redis default
/etc/init.d/redis start
MASTER
We bind the service to all IPs and assign an access password:
vi /etc/redis.conf
bind 0.0.0.0
requirepass PASSWORD
We apply the configuration:
/etc/init.d/redis restart
SLAVE
We indicate to the Slave which is its Master and the associated password. Additionally, we assign an access password to itself:
vi /etc/redis.conf
bind 0.0.0.0
requirepass PASSWORD2
slaveof MASTER_IP 6379
masterauth PASSWORD
/etc/init.d/redis restart
We check that it is synchronized:
redis-cli -a PASSWORD2 info
# Replication
role:slave
master_host:MASTER_IP
master_port:6379
master_link_status:up