Rebuilding a Redis Cluster
The cluster information is automatically maintained when creating a Redis cluster in cluster mode. After the migration is complete, you need to rebuild the cluster.
Prerequisites
If the OS is not connected to the Internet, you need to configure the OS yum, APT, or Zypper source.
Procedure
- Install Redis on all target servers.
- Method 1: Compile source code.
Refer to the Redis Installation and Deployment Tutorials. Select an OS version as required.
- Download the source package of the target version.
- Decompress the Redis package.
1tar -zxvf redis-{version}.tar.gz
- Go to the directory where the Redis source package is decompressed.
1cd redis-{version}
- Perform the compilation.
1make
Redis 5.0 and later versions support systemd, and Redis 6.0 and later versions support TLS. Select the required compilation options.
1make USE_SYSTEMD=yes BUILD_TLS=yes
(1). If a message is displayed indicating that OpenSSL is missing when you execute TLS, install the OpenSSL development library.
1sudo yum install openssl openssl-devel
(2). If a message is displayed indicating that the development library is missing when you execute systemd, install the systemd development library.
1sudo yum install systemd-devel
- 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.
- Method 1: Compile source code.
- Optional: After the installation is complete, you can configure systemd.
- Copy the default Redis service to /usr/lib/systemd/system. You can run the following command to query the redis.service file path:
1find / -name redis.service
- Open the redis.service file and change the value of ExecStart to the following:
1ExecStart={install_path}/bin/redis-server {conf_path}
- Load redis.service.
1systemctl daemon-reload - Start the Redis service.
1systemctl start redis.service
- Check whether the service has been started.
1systemctl status redis.service
If the Active field reads "active (running)", the service is started.
- Copy the default Redis service to /usr/lib/systemd/system. You can run the following command to query the redis.service file path:
- Start the Redis service.
- Method 1: Use the built-in script of Redis.
1${redis-server_directory} ${redis.conf_directory}
- Method 2: Use systemd.
- Start the Redis service.
1systemctl start redis.service
- Check whether the service has been started.
1systemctl status redis.service
If the Active field reads "active (running)", the service is started.
- Start the Redis service.
Ensure that all Redis instances involved in the cluster have been started and are running in cluster mode. That is, set cluster-enabled to yes and set cluster-config-file accordingly in the redis.conf file.
- Method 1: Use the built-in script of Redis.
- Select a proper command based on the Redis version to build a cluster.
- For Redis 4.1.14 and earlier versions:If the migration target is Redis 4.1.14 or earlier, go to the directory where the redis-trib.rb script is stored and run the following command to build the cluster:
1 2 3
./redis-trib.rb create --replicas 1 \ <Node_1_IP_address>:<Port_1> <Node_2_IP_address>:<Port_2> <Node_3_IP_address>:<Port_3> \ <Node_4_IP_address>:<Port_4> <Node_5_IP_address>:<Port_5> <Node_6_IP_address>:<Port_6>
- Replace the example IP addresses and ports with the actual ones.
- You are advised to run this script on any node in the cluster or a dedicated management node.
If the build fails, check the redis-trib.rb dependency.
- Check whether Ruby has been installed.
1ruby -vIf Ruby is not installed, the system displays "command not found" or a similar error.
- Install Ruby.
1sudo yum install ruby -y
- Download the required version of Redis gem or run the following command to install the specified version (using version 4.1.0 as an example):
1gem install redis -v 4.1.0
- After Ruby and Redis gem are installed, go to the directory where the redis-trib.rb script is stored and run the cluster build command again.
1 2 3
./redis-trib.rb create --replicas 1 \ <Node_1_IP_address>:<Port_1> <Node_2_IP_address>:<Port_2> <Node_3_IP_address>:<Port_3> \ <Node_4_IP_address>:<Port_4> <Node_5_IP_address>:<Port_5> <Node_6_IP_address>:<Port_6>
- For Redis 6.2.14:If the migration target is Redis 6.2.14, run the redis-cli command to build the cluster.
1 2 3 4
redis-cli --cluster create \ <Node_1_IP_address>:<Port_1> <Node_2_IP_address>:<Port_2> <Node_3_IP_address>:<Port_3> \ <Node_4_IP_address>:<Port_4> <Node_5_IP_address>:<Port_5> <Node_6_IP_address>:<Port_6> \ --cluster-replicas 1
- Replace the example IP addresses and ports with the actual ones.
- You are advised to run this command on any node in the cluster or a dedicated management node.
- For Redis 4.1.14 and earlier versions:
- On any node in the target cluster, perform the following operation to query the master node of the Redis cluster:
Go to the src directory of Redis and run redis-cli to connect to the Redis instance. The default port is 6379.
1 2
./redis-cli -c -p 6379 cluster nodes
- Install the RedisShake tool and use the tool to migrate Redis data files on each node. The tool configuration varies depending on the version. The following uses v4.1.1 as an example.
- Download the RedisShake tool and upload the downloaded installation package to each target node. The following uses the /home/redisShake/ directory as an example.
1mkdir -p /home/redisShake/
- Decompress the installation package.
1tar xzvf redis-shake-linux-arm64.tar.gz -C /home/redisShake/
- Go to the directory generated after the decompression and modify the shake.toml configuration file.
- Reader configuration items to be commented out: [sync_reader] and [scan_reader]
- Used reader configuration items: [rdb_reader], [aof_reader], and [redis_writer]
- Modify the filepath field in [rdb_reader] and [aof_reader] based on the source data file path. If both [rdb_reader] and [aof_reader] are configured, [rdb_reader] has a higher priority.
- Set the cluster field of [redis_writer] to true.
- Set the address field of [redis_writer] to <Node_IP_Address>:<Port>, which can be the IP address and port of any master node.
The following is an example. Retain the default values for other parameters or modify them as required.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[rdb_reader] filepath = "/devkit_sysmig_disk/path/to/your/redis/data/dump.rdb" [aof_reader] filepath = "/devkit_sysmig_disk/path/to/your/redis/data/appendonly.aof" timestamp = 0 # subsecond [redis_writer] cluster = true # set to true if target is a redis cluster sentinel = false # set to true if target is a redis sentinel master = "" # set to master name if target is a redis sentinel address = "ip:port" # when cluster is true, set address to one of the cluster node username = "" # keep empty if not using ACL password = "" # keep empty if no authentication is required tls = false off_reply = false # turn off the server reply
- Start the migration.
1./redis-shake shake.tomlIf "all done" is displayed in the command output or log, the synchronization is complete.
- Download the RedisShake tool and upload the downloaded installation package to each target node. The following uses the /home/redisShake/ directory as an example.
- On any node of the target cluster, run the get key command to check whether data has been migrated. key indicates the key value of the source Redis. Replace it with the actual key value.
Go to the src directory of Redis and run redis-cli to connect to the Redis instance. The default port is 6379.
1 2
./redis-cli -c -p 6379 get key
If the key exists, it is returned.