Getting started with redis5 cluster cluster

Keywords: Database Redis

I. modify the configuration file

#Start port

port 5001

#Background operation

daemonize yes

#Process ID file storage location

pidfile /var/run/

#Log ID file storage location

logfile /home/whqlkj/redis-cluster/5001/redis-server.log

#Data file storage location

dir /home/whqlkj/redis-cluster/5001/

#AOF persistence

appendonly yes

#Open cluster

cluster-enabled yes

#Cluster profile

cluster-config-file nodes-6379.conf

#Cluster profile

cluster-config-file nodes-5001.conf

#Cluster node timeout

cluster-node-timeout 15000

II. Start all node services

There is only one example in this article

$redis-server /home/zrj/redis-cluster/5001/redis.conf

3. Create a cluster

$ redis-cli --cluster create \ \ \ \ \ \
--cluster-replicas 1

IV. use and view cluster status

#Mode of client entering cluster

-c Enable cluster mode Turn on cluster mode
-h <hostname> Server hostname (default:
-p <port> Server port (default: 6379).

#Use practice

$ redis-cli -c -h -p 5001> set name zhangsan
-> Redirected to slot [5798] located at
OK> get name

#View cluster status

$cluster info



#clusterstate: ok indicates that the cluster can normally accept query requests. The fail state indicates that at least one hash slot is not bound (indicating that there is a hash slot that is not bound to any node), or in the wrong state (the node can provide services but has a fail flag), or the node cannot contact most master nodes.


#Cluster? Slots? Assigned: number of hash slots allocated to cluster nodes (not unbound). 16384 hash slots are all allocated to the cluster nodes, which is the necessary condition for the normal operation of the cluster.


#Cluster? Slots? OK: hash slot status is not the number of FAIL and PFAIL


#Hash slot status is the number of PFAIL. As long as the hash slots are not upgraded to FAIL, they can still be processed normally. The PFAIL state means that we cannot interact with the node at present, but this state is only a temporary error state.


#Hash slot status is the number of failures. If the value is not 0, the cluster node will not be able to provide query service unless cluster require full coverage is set to no


#The number of nodes in the cluster, including those in handshake state that have not become formal members of the cluster


#The number of master nodes that contain at least one hash slot and can provide services


#View cluster nodes

$cluster nodes

Through this information, you can view the master-slave relationship before each node

b3363a81c3c59d57143cd3323481259c044e66d2 slave 1b7aa419065c5477c0def9d5e25106963fbdda76 0 1572917132045 6 connected
9dc870942555447543694e42e40061823ed91271 slave d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 0 1572917130038 4 connected
1b7aa419065c5477c0def9d5e25106963fbdda76 master - 0 1572917131041 3 connected 10923-16383
b1b67d4e554e29605bdbe40deab6670a42dd8836 master - 0 1572917130000 2 connected 5461-10922
fbf9f23ecf0fea399debf7db42c73fece04b98fd slave b1b67d4e554e29605bdbe40deab6670a42dd8836 0 1572917131000 5 connected
d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 myself,master - 0 1572917127000 1 connected 0-5460

Posted by freeheader on Mon, 04 Nov 2019 19:11:53 -0800