Rate This Document
Findability
Accuracy
Completeness
Readability

Configuring Redis

This section describes how to set the Redis master/slave replication environment on a server.

  1. Create Redis running directories.
    Create a main directory /home/redis/replication and two subdirectories 6380 and 6381 for storing configuration files and data files of two Redis instances (one master node and one slave node), respectively.
    mkdir -p /home/redis/replication
    cd /home/redis/replication
    mkdir 6380 6381
  2. Copy the default configuration file.

    Copy redis.conf in the Redis installation package to the /home/redis/replication/6380 directory on the master node.

    cp /home/redis-6.0.20/redis.conf /home/redis/replication/6380
  3. Modify the configuration file of the master node.
    1. Switch to the /home/redis/replication/6380 directory where the configuration file of the master node is stored.
      cd /home/redis/replication/6380
    2. Run the sed commands to modify the configuration file.
      sed -i "s/bind 127.0.0.1/#bind 127.0.0.1/g" redis.conf
      sed -i "s/protected-mode yes/protected-mode no/g" redis.conf
      sed -i "s/# ignore-warnings ARM64-COW-BUG/ignore-warnings ARM64-COW-BUG/g" redis.conf
  4. Copy and modify the configuration file of the slave node.
    1. Copy the redis.conf configuration file on the master node to the /home/redis/replication/6381 directory on the slave node.
      cp redis.conf /home/redis/replication/6381
    2. In the configuration file of the slave node, add slaveof 127.0.0.1 6380 to specify the Redis instance as the slave node and set its master node as the Redis instance running on port 6380 of the local host (IP address: 127.0.0.1).

      cd /home/redis/replication/6381
      echo "slaveof 127.0.0.1 6380" >> redis.conf