redis 5.0 cluster building

In October 2018, Redis released a stable version of 5.0 and introduced various new features. One of them is to give up Ruby's cluster mode and change to Redis cli mode written in C language, which greatly reduces the complexity of cluster construction. Here is a description of cluster building

1. Download redis first

​wget http://download.redis.io/releases/redis-5.0.0.tar.gz
tar xzf redis-5.0.0.tar.gz
cd redis-5.0.0
make

2. Install redis

cd src
make install PREFIX=/home/hui/software/redis

3. Create cluster folder

mkdir redis-cluster
cd redis-cluster/
mkdir 7001
mkdir 7002
mkdir 7003
mkdir 7004
mkdir 7005
mkdir 7006

4. Copy the redis installation script

cp ./redis.conf /bin
cp -r ./bin/* ./redis-cluster/700[1-6]

5. Modify the configuration file (redis.conf)

port 7001  #port
bind 192.168.43.11 #Host ip
cluster-enabled yes #Enable cluster mode
cluster-config-file nodes.conf #Auto generated node configuration
cluster-node-timeout 5000 #Timeout time
appendonly yes
daemonize yes #Background operation
protected-mode no #Unprotected mode
pidfile /home/hui/software/redis/redis-cluster/7001/7001.pid

port and pidfile need to be increased with different folders

6. Write startup script

vim start-all.sh, as follows

cd /home/hui/software/redis/redis-cluster/7001
./redis-server ./redis.conf

cd /home/hui/software/redis/redis-cluster/7002
./redis-server ./redis.conf

cd /home/hui/software/redis/redis-cluster/7003
./redis-server ./redis.conf

cd /home/hui/software/redis/redis-cluster/7004
./redis-server ./redis.conf

cd /home/hui/software/redis/redis-cluster/7005
./redis-server ./redis.conf

cd /home/hui/software/redis/redis-cluster/7006
./redis-server ./redis.conf

7. Start the instance

sh start-all.sh 

8. Write startup cluster script

vim start-cluster.sh, as follows

/home/hui/software/redis/src/redis-cli --cluster create 192.168.43.11:7001 192.168.43.11:7002 192.168.43.11:7003 192.168.43.11:7004 192.168.43.11:7005 192.168.43.11:7006 --cluster-replicas 1

Start cluster: SH start-cluster.sh, the result is as follows:

[hui@hadoop11 redis-cluster]$ sh start-cluster.sh 
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.43.11:7004 to 192.168.43.11:7001
Adding replica 192.168.43.11:7005 to 192.168.43.11:7002
Adding replica 192.168.43.11:7006 to 192.168.43.11:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 2a4e1320781105790a61051b84efc640dff19fed 192.168.43.11:7001
   slots:[0-5460] (5461 slots) master
M: 1bca19101b9556bf688ff35ce7b7905083474c3e 192.168.43.11:7002
   slots:[5461-10922] (5462 slots) master
M: 69f1bca60c7833b4bf6866b40334c1cacc24d0f2 192.168.43.11:7003
   slots:[10923-16383] (5461 slots) master
S: 8dfcdee38afceabf0e0bdad56f51b2cd4be07ba8 192.168.43.11:7004
   replicates 1bca19101b9556bf688ff35ce7b7905083474c3e
S: 26985f449573ea6bd67e97046d14fcb354494f1c 192.168.43.11:7005
   replicates 69f1bca60c7833b4bf6866b40334c1cacc24d0f2
S: 5b7b86078ae011aa64ecf1590083358ea80a6295 192.168.43.11:7006
   replicates 2a4e1320781105790a61051b84efc640dff19fed
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
...
>>> Performing Cluster Check (using node 192.168.43.11:7001)
M: 2a4e1320781105790a61051b84efc640dff19fed 192.168.43.11:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 69f1bca60c7833b4bf6866b40334c1cacc24d0f2 192.168.43.11:7003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 5b7b86078ae011aa64ecf1590083358ea80a6295 192.168.43.11:7006
   slots: (0 slots) slave
   replicates 2a4e1320781105790a61051b84efc640dff19fed
S: 8dfcdee38afceabf0e0bdad56f51b2cd4be07ba8 192.168.43.11:7004
   slots: (0 slots) slave
   replicates 1bca19101b9556bf688ff35ce7b7905083474c3e
S: 26985f449573ea6bd67e97046d14fcb354494f1c 192.168.43.11:7005
   slots: (0 slots) slave
   replicates 69f1bca60c7833b4bf6866b40334c1cacc24d0f2
M: 1bca19101b9556bf688ff35ce7b7905083474c3e 192.168.43.11:7002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

View cluster status

cd 7001
./redis-cli -c -p 7001 -h 192.168.43.11


cluster nodes #View node status

Reference resources: https://my.oschina.net/ruoli/blog/2252393

Tags: Programming Redis vim Ruby C

Posted on Fri, 08 Nov 2019 16:12:05 -0500 by bennyboywonder