Detailed redis cluster cluster architecture (XV) - redis cluster commonly used commands

5.8. Cluster commonly used commands

5.8.1. Restart and remove a cluster

View redis cluster command:

Here Insert Picture Description

1. Shut down one node in the cluster

Shut down the cluster of a node, such as closing the port number 7001 as an example:

redis-cli -a cyclone -c -h 192.168.75.187 -p 7001 shutdown

Implementation of the results is as follows:

Here Insert Picture Description

After closing, the following command can be restarted

redis-server /etc/redis/redis-cluster-7001/7001.conf

Command to restart instance, after the startup is completed, which is automatically added to the cluster.

Here Insert Picture Description

Off 2. Cluster

Redis closed one by one instance of a process to
find redis instance process ID

    ps -ef | grep redis

Here Insert Picture Description

Redis off process, using the process ID kill -9 $ {}, if necessary to close a plurality of processes, can be separated by a space between the process number

kill -9 3535 3540 3545 3550 3555 24822

也可执行以下命令来关闭redis进程
pkill -9 redis

Restart the cluster 3.redis

Restart redis clusters of two ways: keep the original data, discard the original data.

(1) retain the original data:
one by one off redis example, then one by one to the start.

(2) discard the original data:

关闭实例,清空实例中数据存放目录的所有内容,然后逐个启动实例,在任意一个实例上执行集群的创建命令即可,本质上就是创建一个新的集群

Empty the contents of the data storage directory:

   rm -rf /etc/redis/redis-cluster-7001/data/*
   rm -rf /etc/redis/redis-cluster-7002/data/*
   rm -rf /etc/redis/redis-cluster-7003/data/*
   rm -rf/etc/redis/redis-cluster-7004/data/*
   rm -rf /etc/redis/redis-cluster-7005/data/*
   rm -rf /etc/redis/redis-cluster-7006/data/*

Start the instance:

  redis-server /etc/redis/redis-cluster-7001/7001.conf
  redis-server /etc/redis/redis-cluster-7002/7002.conf
  redis-server /etc/redis/redis-cluster-7003/7003.conf
  redis-server /etc/redis/redis-cluster-7004/7004.conf
  redis-server /etc/redis/redis-cluster-7005/7005.conf
  redis-server /etc/redis/redis-cluster-7006/7006.conf

Perform cluster creation command:

redis-cli --cluster create 192.168.75.187:7001 192.168.75.187:7002 192.168.75.187:7003 192.168.75.187:7004 192.168.75.187:7005 192.168.75.187:7006 --cluster-replicas 1

5.8.2.create create a cluster

  • create
  • -replicas # optional parameters, replicas represent each master needs to have several slave.

create replicas optional command parameters, replicas expressed the need to have several slave.

5.8.3. Viewing Cluster


Information CLUSTER INFO print cluster

[root@cache01 src]# redis-cli -h 192.168.75.187 -p 7001 cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:9924
cluster_stats_messages_pong_sent:9471
cluster_stats_messages_sent:19395
cluster_stats_messages_ping_received:9466
cluster_stats_messages_pong_received:9924
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:19395
[root@cache01 src]# 

CLUSTER NODES list all cluster nodes (node) currently known, as well as information about these nodes.

[root@cache01 src]# redis-cli -h 192.168.75.187 -p 7001 cluster nodes
ac47bd2d21c50500cc59c0f35720801f49e8cbba 192.168.75.187:7005@17005 slave 97901b9d1281fb8b27b26898340ec1682dfffdba 0 1584007216062 5 connected
c276f98fb8f6b74cccceb3eb7399702fa6644cd9 192.168.75.187:7003@17003 master - 0 1584007217072 3 connected 10923-16383
3605efaeea1afcfd373f17181cf09a02915aa098 192.168.75.187:7004@17004 slave c276f98fb8f6b74cccceb3eb7399702fa6644cd9 0 1584007218081 4 connected
e59bc95e8fadbcc1acaf95ada1621b8594c48007 192.168.75.187:7006@17006 slave d3316138a3d30dbaeceda65fc6fb8a2eeaeb2143 0 1584007215000 6 connected
d3316138a3d30dbaeceda65fc6fb8a2eeaeb2143 192.168.75.187:7002@17002 master - 0 1584007216000 2 connected 5461-10922
97901b9d1281fb8b27b26898340ec1682dfffdba 192.168.75.187:7001@17001 myself,master - 0 1584007217000 1 connected 0-5460 

5.8.4. Node (node) command

1, ip and adding nodes to a port designated cluster

CLUSTER MEET <ip> <port>

2, remove node_id specified node from the cluster

CLUSTER FORGET <node_id>

3, the node specified for the node from the current node node_id

CLUSTER REPLICATE <node_id>

4, the node configuration file is saved to the hard disk inside

CLUSTER SAVECONFIG

5.8.5. Slot (slot) Command

1, one or more slots (slot) is assigned (ASSIGN) to the current node

CLUSTER ADDSLOTS <slot> [slot ...]

2, the removal of one or more slots assigned to the current node

CLUSTER DELSLOTS <slot> [slot ...]

3, remove all slots assigned to the current node, so that the current node becomes a node is not assigned to any slot

CLUSTER FLUSHSLOTS

4, the groove node_id slot assigned to the specified node, if the slot has been assigned to another node, then the node deletes the other groove let>, and then to assign

CLUSTER SETSLOT <slot> NODE <node_id>

5, the slot groove migration node_id node to the specified node

CLUSTER SETSLOT <slot> MIGRATING <node_id>

6, introduced into the groove slot node_id node from the specified node

CLUSTER SETSLOT <slot> IMPORTING <node_id>

7, cancel the import of the slot grooves (Import) or migration (the migrate)

CLUSTER SETSLOT <slot> STABLE

5.8.6. Key command key

1, calculates the key should be placed in the key slot on which

CLUSTER KEYSLOT <key>

2, the key return slot number contained in the current slot

CLUSTER COUNTKEYSINSLOT <slot>

3, a return slot count slot key

CLUSTER GETKEYSINSLOT <slot> <count>
Published 155 original articles · won praise 23 · views 110 000 +

Guess you like

Origin blog.csdn.net/makyan/article/details/104798899
Recommended