Configuring the Redis Cluster
Preparations include creating running directories, copying and modifying the default configuration file, and copying the modified configuration file to other node directories.
- Create Redis running directories.
Create a directory named cluster to store all related files and directories of the Redis cluster. Create six subdirectories (6380 to 6385) in the cluster directory. Each subdirectory stores the configuration file and data files of one Redis instance.
mkdir -p /home/redis/cluster cd /home/redis/cluster mkdir 6380 6381 6382 6383 6384 6385
- Copy the default configuration file.
Copy the default configuration file redis.conf in the Redis installation package to the /home/redis/cluster/6380 directory on the first node in the cluster.
cp /home/redis-6.0.20/redis.conf /home/redis/cluster/6380
- In the 6380 node directory, run the sed commands to modify the configuration file.
cd /home/redis/cluster/6380 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 echo cluster-enabled yes >> redis.conf echo cluster-config-file nodes-cluster.conf >> redis.conf echo cluster-node-timeout 15000 >> redis.conf
Three cluster-related commands are added to the configuration file:
- cluster-enabled yes: enables the Redis cluster mode.
- cluster-config-file nodes-cluster.conf: specifies the name and location of the cluster node configuration file.
- cluster-node-timeout 15000: specifies the connection timeout interval of cluster nodes, in milliseconds.
- Copy the configuration file to other nodes.
Copy the modified redis.conf configuration file in the 6380 directory to the directories (from 6381 to 6385) on the other five nodes.
cp redis.conf /home/redis/cluster/6381 cp redis.conf /home/redis/cluster/6382 cp redis.conf /home/redis/cluster/6383 cp redis.conf /home/redis/cluster/6384 cp redis.conf /home/redis/cluster/6385