To set up a Redis master-slave replication on Debian 12, you’ll follow these general steps on each server to configure the master and slave nodes:

Step 1: Install Redis

  1. Update your package list:
  1. Install Redis:
  1. Enable and start Redis on each server:

Step 2: Configure Redis Master

  1. Edit the Redis configuration file on the master server (/etc/redis/redis.conf):
  • Set a bind IP (default is 127.0.0.1). You may want to change it to the server’s internal IP if necessary: bind 0.0.0.0
  • Enable persistence (optional but recommended) by setting: appendonly yes
  • Restart Redis to apply changes:
    bash sudo systemctl restart redis-server
  1. Verify the master server is running correctly by connecting locally or remotely (depending on your setup).

Step 3: Configure Redis Slave

On the slave server(s), edit the configuration to connect to the master server.

  1. Edit the Redis configuration file on each slave (/etc/redis/redis.conf):
  • Set the IP for the slave to listen to, or leave it as the default 127.0.0.1.
  • Add the master server’s IP address and port (default is 6379): replicaof <master_ip> <master_port>
  • Set a password if your master server has one (optional): masterauth <your_master_password>
  • Restart Redis on the slave to apply the configuration:
    bash sudo systemctl restart redis-server

Step 4: Testing the Replication

  1. On the master server, add a key-value pair using the Redis CLI:
  1. On the slave server, check if the data is available by fetching test_key:

If replication is working, you should see the same value.

Step 5: Monitor Replication

To check the replication status:

  • On the master server, run:

It should show connected_slaves: 1 or more, depending on the number of slaves.

  • On each slave server, run:

It should show role:slave and master_link_status: up.

Optional Step: Securing Redis

  1. Set up a Redis password on the master by editing /etc/redis/redis.conf:
  1. Update the masterauth parameter on the slave(s) to match this password.
  2. Restart Redis on all servers to apply the changes.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.