I. modify the configuration file
#Start port
port 5001
#Background operation
daemonize yes
#Process ID file storage location
pidfile /var/run/redis_6379.pid
#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 192.168.8.196:5001 \
192.168.8.196:5002 \
192.168.8.196:5003 \
192.168.8.196:5004 \
192.168.8.196:5005 \
192.168.8.196:5006 \
--cluster-replicas 1
IV. use and view cluster status
#Mode of client entering cluster
redis-cli
-c Enable cluster mode Turn on cluster mode
-h <hostname> Server hostname (default: 127.0.0.1).
-p <port> Server port (default: 6379).
#Use practice
$ redis-cli -c -h 192.168.8.196 -p 5001
192.168.8.196:5001> set name zhangsan
-> Redirected to slot [5798] located at 192.168.8.196:5002
OK
192.168.8.196:5002> get name
"zhangsan"
#View cluster status
$cluster info
Interpretation:
cluster_state:ok
#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:16384
#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:16384
#Cluster? Slots? OK: hash slot status is not the number of FAIL and PFAIL
cluster_slots_pfail:0
#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.
cluster_slots_fail:0
#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
cluster_known_nodes:6
#The number of nodes in the cluster, including those in handshake state that have not become formal members of the cluster
cluster_size:3
#The number of master nodes that contain at least one hash slot and can provide services
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:44701
cluster_stats_messages_pong_sent:39531
cluster_stats_messages_sent:84232
cluster_stats_messages_ping_received:39526
cluster_stats_messages_pong_received:44701
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:84232
#View cluster nodes
$cluster nodes
Through this information, you can view the master-slave relationship before each node
b3363a81c3c59d57143cd3323481259c044e66d2 192.168.8.196:5006@15006 slave 1b7aa419065c5477c0def9d5e25106963fbdda76 0 1572917132045 6 connected 9dc870942555447543694e42e40061823ed91271 192.168.8.196:5004@15004 slave d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 0 1572917130038 4 connected 1b7aa419065c5477c0def9d5e25106963fbdda76 192.168.8.196:5003@15003 master - 0 1572917131041 3 connected 10923-16383 b1b67d4e554e29605bdbe40deab6670a42dd8836 192.168.8.196:5002@15002 master - 0 1572917130000 2 connected 5461-10922 fbf9f23ecf0fea399debf7db42c73fece04b98fd 192.168.8.196:5005@15005 slave b1b67d4e554e29605bdbe40deab6670a42dd8836 0 1572917131000 5 connected d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 192.168.8.196:5001@15001 myself,master - 0 1572917127000 1 connected 0-5460