Rate This Document
Findability
Accuracy
Completeness
Readability

Migrating from Redis to Redis

  1. Install Redis on the target server.
    • Method 1: Compile and install the source code. For details, see the Redis official installation and deployment tutorials.
      1. Download the source package of the required version and decompress it. Replace version with the actual version.
        tar -zxvf redis-{version}.tar.gz
      2. Go to the directory where the Redis package is decompressed.
        cd redis-{version}
      3. Perform the compilation.
        1
        make
        

        Redis 5.0 and later versions support systemd, and Redis 6.0 and later versions support TLS. Select the required compilation options.

        1
        make USE_SYSTEMD=yes BUILD_TLS=yes
        
        • If a message is displayed indicating that OpenSSL is missing when you execute TLS, install the OpenSSL development library.
          1
          sudo yum install openssl openssl-devel
          
        • If a message is displayed indicating that the development library is missing when you execute systemd, install the systemd development library.
          1
          sudo yum install systemd-devel
          
      4. Run the make install command. You can use the default installation address or use PREFIX to specify the installation address.
        1
        2
        make install
        make PREFIX={install_path} install
        
    • Method 2: Use the software package management tool.

      Run the install command. However, this installation method does not support TLS.

      1
      sudo yum install redis
      
  2. (Optional) After the installation is complete, you can configure systemd.
    1. Copy the default Redis service to the /usr/lib/systemd/system path. You can run the following command to query the redis.service file path:
      1
      find / -name redis.service
      
    2. Modify the redis.service file.
      1. Open the redis.service file.
        1
        vi redis.service
        
      2. Press i to enter the insert mode and modify ExecStart=.
        1
        ExecStart={install_path}/bin/redis-server {conf_path}
        
      3. Press Esc, type :wq!, and press Enter to save the file and exit.
    3. Load redis.service.
      1
      systemctl daemon-reload
      
    4. Start the Redis service.
      1
      systemctl start redis.service
      
    5. Check whether the service is started.
      1
      systemctl status redis.service
      

      If the Active field reads "active (running)", the service has been started.

    6. Stop the Redis service.
      1
      systemctl stop redis.service
      
  3. Migrate configuration and data files.

    Run commands on the source server to locate the configuration and data files, and then find the corresponding files in the mount directory of the target server. Then start the configuration and data files. If multiple Redis instances are running on a server, you need to migrate configuration and data files for each instance separately.

    • Migrating configuration files

      Go to the src directory of Redis, start the redis-server and redis-cli services, and run the following command in redis-cli:

      1
      INFO
      

      Find config_file: and record the configuration file address. Replace the redis.conf file in the installation directory with this configuration file. If config_file: is empty, no configuration file is specified during startup. In this case, skip this step.

    • Migrating data files
      1. Go to the src directory of Redis, start the redis-server and redis-cli services, and run the following command in redis-cli:
        1
        save
        
      2. Run the following command in the redis-cli service to check whether appendonly is enabled:
        1
        CONFIG GET appendonly
        
        • If the appendonly parameter is set to no, the AOF function is disabled. In this case, you do not need to migrate the AOF file.
        • If the appendonly parameter is set to yes, proceed to the next step.
      3. Obtain the Redis data directory.
        1
        CONFIG GET dir
        
      4. Migrate the AOF file (AOF records each write operation received by the server).
        Go to the dir directory and migrate the AOF files to the dir directory specified in the Redis configuration file on the target server. If dir is set to ./, migrate the AOF file to the corresponding location in the relative path of Redis installed on the target server. The following conditions must be met:
        • The AOF name file is the same as the value of appendfilename in the configuration file.
        • The AOF policy is enabled for the Redis application (the appendonly parameter in the configuration file is set to yes).
      5. Migrate the RDB file (RDB persistently takes point-in-time snapshots of the dataset).

        Query the RDB file name:

        1
        CONFIG GET dbfilename
        

        Go to the found dir directory, search for the RDB file based on the output file name, and migrate the RDB file to the dir directory specified in the Redis configuration file on the target server. Ensure that the RDB file name is the same as the value of dbfilename in the configuration file. If dir is set to ./, migrate the RDB file to the corresponding location in the relative path of Redis installed on the target server.

    • Migrating the cluster
      1. If the original Redis is deployed in cluster mode, migrate the cluster configuration file to the new Redis server and perform the following operation again:
        1
        CONFIG GET dir
        
      2. Go to the found dir directory. The cluster configuration file is usually named nodes.conf. If the file name has been changed, migrate all .conf files. Migrate these files to the dir directory on the target server to ensure that the cluster configurations are consistent.
  4. (Optional) If Redis is deployed in active/standby mode, modify related settings.
    • If the current node is the active node, modify the configuration file (redis.conf by default).
      • bind: Change the value to the IP address of the current active node.
      • logfile and dir: Set them to the correct log and data addresses. Absolute paths are recommended.
      • masterauth: Enter the correct authentication password of the active node.
      • requirepass: Enter the correct CLI authentication password of the active node.
    • If the current node is the standby node, modify the configuration file (redis.conf by default).
      • bind: Change the value to the IP address of the current standby node.
      • logfile and dir: Set them to the correct log and data addresses. Absolute paths are recommended.
      • masterauth: Enter the correct authentication password of the standby node.
      • requirepass: Enter the correct CLI authentication password of the standby node.
      • replicaof (slaveof in versions earlier than 5.0.0): Replace it with the correct IP address and port of the active node.
    • If a sentinel is deployed on the current node, migrate the sentinel configuration file to the correct path and modify the following configuration (sentinel.conf by default):
      • sentinel monitor mymaster: Change the value to the IP address and port of the active node.
      • sentinel auth-pass mymaster: Change the value to the correct authentication password of the active node.

    You can also configure the active/standby and sentinel nodes on other machines in the same way.

  5. Start the Redis service.
    • Method 1: Use the built-in script of Redis to start the service. (If the original service uses a specified configuration file, use the configuration file in the original path to restart the service.)
      1
      /usr/local/bin/redis-server
      
    • Method 2: Use systemd.
      1. Start the Redis service.
        1
        systemctl start redis.service
        
      2. Check whether the service is started.
        1
        systemctl status redis.service
        

        If the Active field reads "active (running)", the service has been started.

  6. (Optional) If Redis is deployed in active/standby mode, start the Redis sentinel nodes based on your service requirements.