Redis Cluster basic setup
Disclaimer: Make sure to use Redis 5 to follow along this quick guide, if using the older distribution, please refer to Official Documentation for more information.
This works on Redhat 7, to install Redis 5
#Set up repo
rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
# install redis
yum install -y redis --enablerepo=remi
This creates 3 shards and 3 replicas
Client we are using here is the redis-cli command line tool
ShardX, SalveX are redis-server processes
#create conf files
node1.conf
------------------
port 7001
cluster-enabled yes
cluster-config-file cluster-node-1.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-1.aof
dbfilename dump-1.rdb
.
.
.
node6.conf
------------------
port 7006
cluster-enabled yes
cluster-config-file cluster-node-6.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-6.aof
dbfilename dump-6.rdb
#Start each redis-server node
--------------------------------------
redis-server node1.conf &
.
.
.
redis-server node6.conf &
#verify the processes are running
pgrep -lfa redis
----------------
28228 redis-server *:7001 [cluster]
28233 redis-server *:7002 [cluster]
28237 redis-server *:7003 [cluster]
28242 redis-server *:7004 [cluster]
28246 redis-server *:7005 [cluster]
28250 redis-server *:7006 [cluster]
#once the processes started, we can see it automatically created
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-3.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-4.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-5.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-6.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-1.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-2.conf
#create redis cluster by specifying the ports and note we are creating cluster with replicas of 1
redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1
#trying it out
redis-cli -c -p 7001
127.0.0.1:7001> set hobby basketball
-> Redirected to slot [8496] located at 127.0.0.1:7002
OK
127.0.0.1:7002> 127.0.0.1:7002> get hobby
"basketball"
# we are directed to the master of the shard
# use "cluster nodes" command to check the master slave information
127.0.0.1:7001> cluster nodes
7ffa5d49ab1b11509a4a0affdb417e50f9c20000 127.0.0.1:7006@17006 slave 06c291e4565c70f7617255bf96f5824724b8dc8c 0 1575925486503 6 connected
379d5b7d33fcb4a4905066d01242e54e01f17241 127.0.0.1:7001@17001 myself,master - 0 1575925487000 1 connected 0-5460
2dfa3c1780087c7a98f8dff4f9d89bef0764fd31 127.0.0.1:7005@17005 slave 379d5b7d33fcb4a4905066d01242e54e01f17241 0 1575925487000 5 connected
288775b27ab7064c41bcdf93da1d25dcde7e4426 127.0.0.1:7004@17004 slave 5c300e92a4e814bcbd63e454d563014837bc5f45 0 1575925487607 4 connected
06c291e4565c70f7617255bf96f5824724b8dc8c 127.0.0.1:7002@17002 master - 0 1575925488107 2 connected 5461-10922
5c300e92a4e814bcbd63e454d563014837bc5f45 127.0.0.1:7003@17003 master - 0 1575925486000 3 connected 10923-16383
This works on Redhat 7, to install Redis 5
#Set up repo
rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
# install redis
yum install -y redis --enablerepo=remi
This creates 3 shards and 3 replicas
Client we are using here is the redis-cli command line tool
ShardX, SalveX are redis-server processes
#create conf files
node1.conf
------------------
port 7001
cluster-enabled yes
cluster-config-file cluster-node-1.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-1.aof
dbfilename dump-1.rdb
.
.
.
node6.conf
------------------
port 7006
cluster-enabled yes
cluster-config-file cluster-node-6.conf
cluster-node-timeout 5000
appendonly yes
appendfilename node-6.aof
dbfilename dump-6.rdb
#Start each redis-server node
--------------------------------------
redis-server node1.conf &
.
.
.
redis-server node6.conf &
#verify the processes are running
pgrep -lfa redis
----------------
28228 redis-server *:7001 [cluster]
28233 redis-server *:7002 [cluster]
28237 redis-server *:7003 [cluster]
28242 redis-server *:7004 [cluster]
28246 redis-server *:7005 [cluster]
28250 redis-server *:7006 [cluster]
#once the processes started, we can see it automatically created
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-3.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-4.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-5.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-6.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-1.conf
-rw-r--r-- 1 root root 781 Dec 9 15:02 cluster-node-2.conf
#create redis cluster by specifying the ports and note we are creating cluster with replicas of 1
redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1
#trying it out
redis-cli -c -p 7001
127.0.0.1:7001> set hobby basketball
-> Redirected to slot [8496] located at 127.0.0.1:7002
OK
127.0.0.1:7002> 127.0.0.1:7002> get hobby
"basketball"
# we are directed to the master of the shard
# use "cluster nodes" command to check the master slave information
127.0.0.1:7001> cluster nodes
7ffa5d49ab1b11509a4a0affdb417e50f9c20000 127.0.0.1:7006@17006 slave 06c291e4565c70f7617255bf96f5824724b8dc8c 0 1575925486503 6 connected
379d5b7d33fcb4a4905066d01242e54e01f17241 127.0.0.1:7001@17001 myself,master - 0 1575925487000 1 connected 0-5460
2dfa3c1780087c7a98f8dff4f9d89bef0764fd31 127.0.0.1:7005@17005 slave 379d5b7d33fcb4a4905066d01242e54e01f17241 0 1575925487000 5 connected
288775b27ab7064c41bcdf93da1d25dcde7e4426 127.0.0.1:7004@17004 slave 5c300e92a4e814bcbd63e454d563014837bc5f45 0 1575925487607 4 connected
06c291e4565c70f7617255bf96f5824724b8dc8c 127.0.0.1:7002@17002 master - 0 1575925488107 2 connected 5461-10922
5c300e92a4e814bcbd63e454d563014837bc5f45 127.0.0.1:7003@17003 master - 0 1575925486000 3 connected 10923-16383
Comments
Post a Comment