Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis cluster cluster building (add, delete, modify, check): 5.0.2

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Environment introduction: 1:centos 7; 2:redis version 5.0.2; 3: installation method: compilation and installation; 4:. Create a cluster node IP address: 10.42.166.105VR 6379 10.42.142.202VR 6379 10.42.11.183Rd 6379 10.42.35.2012016379 10.42.181.22RV 6379 10.42.7222379

After starting 6 instances using the company redis docker image, start to create the cluster:

The create command has an optional replicas parameter, and replicas indicates that several slave are required. The simplest commands are as follows:

Redis-cli-- cluster create-- cluster-replicas 1\ 10.42.166.105purl 6379\ 10.42.142.202purl 6379\ 10.42.11.183purl 6379\ 10.42.35.201purl 6379\ 10.42.181.22 cluster-replicas 6379\ 10.42.225.72Partition 6379 view cluster nodes

Redis-cli cluster nodes

Test to create keyset testkey1 testvalue1get testkey1 simulation failure and delete image

Directly delete 10.42.141.119 nodes directly in the rancher cluster

Check the status root@redis-cluster-redis-cluster-test-1:/data# redis-cli cluster nodes21322d2e62d027393a46add604a8eed37c53b460 10.42.1.140 connecteddfa238fff8a7a49230cff7eb74f573f5645c8ec5 6379mm 16379 slave 39cde9a04a9cfde37337840f31fa1bc1ab8fb37a 0 1546933324975 6 connecteddfa238fff8a7a49230cff7eb74f573f5645c8ec5 10.42.166.105VOR 6379v 16379 myself Master-01546933324000 1 connected 0-5460f1e99f5f57b2390cba33c8142cb79c2e062db854 10.42.158.17 5460f1e99f5f57b2390cba33c8142cb79c2e062db854 6379379 master-01546933325980 2 connected 5461-109223f20faa26d09fd263f249976fbdac859d26a511a 10.42.91.228 master 6379mm 16379 slave f1e99f5f57b2390cba33c8142cb79c2e062db854 01546933326981 5 connected39cde9a04a9cfde37337840f31fa1bc1ab8fb37a 10.42.221.21114933325000 3 connected 10923-16383connection # Cluster shows that node connection failed 9460c46ed7e8e9d809a896d966754823c7fb9e5d 10.42.141.119Switzerland 6379U 16379 slave,fail dfa238fff8a7a49230cff7eb74f573f5645c8ec5 154693327432 1546933277829 connected cluster completely deleted nodes from cluster

Removes the node specified by node_id from the cluster.

Redis-cli cluster forget dfa238fff8a7a49230cff7eb74f573f5645c8ec5 returns OK### to delete a node from the cluster del-node can delete a node from the cluster. Del-node can only delete nodes that do not have an assigned slot. The delete command passes two parameters: host:port: get cluster information from this node. Node_id: the node id that needs to be deleted. Redis-cli cluster del-node 10.42.141.211 dfa238fff8a7a49230cff7eb74f573f5645c8ec5 add New Node (add Slave Node)

-- slave: if this parameter is set, the new node joins the cluster as slave

-- master-id: this parameter needs to be set to-- slave to take effect.-- master-id is used to specify the master node of the new node. If you do not set this parameter, the master node is randomly selected for the node.

Redis-cli-- cluster add-node New Node IP address: Port presence Node IP: Port-- cluster-slave (slave node)-- cluster-master-id (ID of master node) redis-cli-- cluster add-node 10.42.141.119IP 6379 10.42.42.166.105 cluster-slave-- cluster-master-id dfa238fff8a7a49230cff7eb74f573f5645c8ec5 returns the following result: > Adding node 10.42.141.119Suzhou 6379 to cluster 10 .42.166.105: 6379 > > Performing Cluster Check (using node 10.42.166.105 slots 6379) M: dfa238fff8a7a49230cff7eb74f573f5645c8ec5 10.42.166.105 slots: [0-5460] (5461 slots) master. [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered. > > Send CLUSTER MEET to node 10.42.141.119 Configure node as replica of 10.42.166.105 join. [OK] New node added correctly. Add a set of cluster nodes

The nodes are as follows:

10.42.42.180 (main)

10.42.22.184 (from)

Method: first add the master node, then add the slave node

Add Primary Node

Redis-cli-cluster add-node New Node IP: Port already exists Node IP: Port

Example:

Redis-cli-- cluster add-node 10.42.42.180 6379 10.42.166.105

Root@redis-cluster-redis-cluster-test-1:/data# redis-cli-- cluster add-node 10.42.42.180 Performing Cluster Check 6379 10.42.166.105 to cluster 6379 > Performing Cluster Check (using node 10.42.166.105) M: 748273d7a0a186d229028edefdcff2711c1c0e0d 10.42.166.105 to cluster 6379. 1 additional replica (s) [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered. > > Send CLUSTER MEET to node 10.42.42.180 to make it join the cluster. "added successfully [OK] New node added correctly. Verify root@redis-cluster-redis-cluster-test-1:/data# redis-cli cluster nodes.b18bef6a47c06a624d1e2ba0f5d83d4c4ce97ff7 10.42.11.183Vue 6379mm 16379 master-01546941402518 3 connected 10923-163836764b152d0d7526b48a16621ff2a4c72f6494622 10.42.142.202 connected 6379V 16379 master-01546941402000 2 connected 5461-10922mm # New Node 0488e5f3e006f0df2806bf0b178a2414b248b1e5 10.42.42.180Rd 6379U 16379 master-01546941402000 0 connected add slave node

Redis-cli-- cluster add-node new node IP address: Port presence node IP: Port-- cluster-slave (slave node)-- cluster-master-id (ID of master node)

Example:

Redis-cli-- cluster add-node 10.42.22.184 cluster-slave-- cluster-master-id 0488e5f3e006f0df2806bf0b178a2414b248b1e5 6379 10.42.42.180

Root@redis-cluster-redis-cluster-test-1:/data# redis-cli-- cluster add-node 10.42.22.184cluster-slave-- cluster-master-id 0488e5f3e006f0df2806bf0b178a2414b248b1e5 > Adding node 10.42.22.184cluster-slave-- cluster-master-id 0488e5f3e006f0df2806bf0b178a2414b248b1e5 > Performing Cluster Check (using node 10.42.42.180) M: 0488e5f3e006f0df2806bf0b178a2414b248b1e5 10.42.42.180 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. > > Send CLUSTER MEET to node 10.42.22.184All nodes agree about slots configuration 6379 to make it join the cluster.Waiting for the cluster to join > Configure node as replica of 10.42.42.180 Configure node as replica of. [OK] New node added correctly. Verify that root@redis-cluster-redis-cluster-test-1:/data# redis-cli cluster nodesf41d8746a1fd31135b0af1737f69a77ec8e6cd26 10.42.225.72 slave b18bef6a47c06a624d1e2ba0f5d83d4c4ce97ff7 01546941516826 6 connected.6764b152d0d7526b48a16621ff2a4c72f6494622 10.42.142.202 master-015469415148222 connected 5461-10922 has been added successfully But there is no slot 0488e5f3e006f0df2806bf0b178a2414b248b1e5 10.42.42.180 slave 0488e5f3e006f0df2806bf0b178a2414b248b1e5 6379mm 16379 master-01546941515825 7 connectedf9bc8def897915d73569b140d1478fbf94d3dbef 10.42.22.184V 6379mm 16379 slave 0488e5f3e006f0df2806bf0b178a2414b248b1e5 015469415150007 connectedrebalance balanced cluster node slot quantity syntax: rebalance host:port-- weight-- auto-weights-- threshold-- use-empty-masters -- timeout-- simulate-- pipeline host:port: this parameter is required It is used to obtain the whole cluster information from one node, which is equivalent to the entrance to get the cluster information. -- weight: the weight of the node, in the format of node_id=weight. If you need to assign weights to multiple nodes, you need to add multiple-- weight parameters, that is,-- weight b31e3a2e=5-- weight 60b8e3a1power5 NodeSecretid can be the prefix of the node name, as long as you ensure that the number of prefix bits can uniquely distinguish the node. Nodes that do not pass-weight default to 1. Auto-weights: this parameter is not used in the rebalance process. -- threshold: the rebalance operation will be performed only if the slot threshold of the node to be migrated exceeds the threshold. The specific calculation method can be found in the fourth step of the rebalance command flow below. -- whether use-empty-masters:rebalance considers master without nodes. By default, master without assigned slot nodes does not participate in rebalance. Set-- use-empty-masters allows nodes without assigned slot to participate in rebalance. -- timeout: sets the timeout for the migrate command. -- simulate: set this parameter to simulate the rebalance operation and prompt the user which slots will be migrated without actually performing the migration operation. -- pipeline: like the pipeline parameter of reshar, define the number of key fetched by the cluster getkeysinslot command at a time. If not passed, the default value is 10. Example:

Redis-cli-- cluster rebalance 10.42.35.20115 cluster-threshold 6379-- cluster-use-empty-masters-- pipeline 10

If you need to perform a simulation to add:-- cluster-simulate

Root@redis-cluster-redis-cluster-test-1:/data# redis-cli-- cluster rebalance 10.42.35.201Performing Cluster Check 6379-- cluster-threshold 1-- cluster-use-empty-masters > Performing Cluster Check (using node 10.42.35.201cluster-use-empty-masters 6379) [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered. > Rebalancing across 4 nodes. Total weight = 4.00Moving 1366 slots from 10.42.142.202 to 6379 to 10.42.42.180 # Moving 1365 slots from 10.42.166.105:6379 to 10.42.42.180:6379#Moving 1365 slots from 10.42.11.183Viru 6379 to 10.42.42.180Rd 637 validate the rebalance result:

Redis-cli cluster nodes

Root@redis-cluster-redis-cluster-test-1:/data# redis-cli cluster nodesf41d8746a1fd31135b0af1737f69a77ec8e6cd26 10.42.225.72 root@redis-cluster-redis-cluster-test-1:/data# redis-cli cluster nodesf41d8746a1fd31135b0af1737f69a77ec8e6cd26 6379379 slave b18bef6a47c06a624d1e2ba0f5d83d4c4ce97ff7 01546942598000 6 connectede538c397a1c8ca6217561a88d72b08b0e513da84 10.42.181.22 connectede538c397a1c8ca6217561a88d72b08b0e513da84 10.42.181.22 slave 6764b152d0d7526b48a16621ff2a4c72f6494622 01546942598000 5 connected39aceb27ccdce533c5cfbf51eb13928d2515fadc 10.42.35.201437915379 16379 slave 748273d7a0a186d229028edefdcff2711c1c0e0d 01546942599807 4 connected6764b152d0d7526b48a16621ff2a4c72f6494622 10.42.142.202 connectede538c397a1c8ca6217561a88d72b08b0e513da84 637979 master-01546942598803 connected 6827-10922748273d7a0a186d229028edefdcff2711c1c0e0d 10.42.166.105 63792599807 myself Master-01546942597000 1 connected 1365-5460b18bef6a47c06a624d1e2ba0f5d83d4c4ce97ff7 10.42.11.1835460b18bef6a47c06a624d1e2ba0f5d83d4c4ce97ff7 637916379 master-01546942598000 3 connected 12288-1638331 additional nodes already have assigned slots f9bc8def897915d73569b140d1478fbf94d3dbef 10.42.22.1845460b18bef6a47c06a624d1e2ba0f5d83d4c4ce97ff7 6379379 slave 0488e5f3e006f0df2806bf0b178a2414b248b1e5 0154692600809 7 connected0488e5f3e006f0df2806bf0b178a2414b248b1e5 10.42.42.180637916379 master-0154692597000 7 connected0-13645461-6826 10923-12287 commonly used command reference: cluster info: printed cluster information cluster nodes: list all the current known nodes of the cluster (node) And information about these nodes. Node cluster meet: add the node specified by ip and port to the cluster and make it part of the cluster. Cluster forget: removes the node specified by node_id from the cluster. Cluster replicate: sets the current node as the slave node of the node specified by node_id. Cluster saveconfig: save the node configuration file to your hard drive. Slot cluster addslots [slot.]: assign (assign) one or more slot to the current node. Cluster delslots [slot.]: removes the assignment of one or more slots to the current node. Cluster flushslots: removes all slots assigned to the current node, making the current node a node with no slots assigned. Cluster setslot node: assign the slot slot to the node specified by node_id. If the slot is already assigned to another node, let the other node delete the slot > before assigning it. Cluster setslot migrating: migrate the slot slot of this node to the node specified by node_id. Cluster setslot importing: import slot slot into this node from the node specified by node_id. Cluster setslot stable: cancel the import (import) or migration (migrate) of slot slot. Key cluster keyslot: calculates which slot the key key should be placed on. Cluster countkeysinslot: returns the number of key-value pairs currently contained in slot slot. Cluster getkeysinslot: returns the keys in count slot slots

Reference documentation:

Http://weizijun.cn/2016/01/08/redis%20cluster%E7%AE%A1%E7%90%86%E5%B7%A5%E5%85%B7redis-trib-rb%E8%AF%A6%E8%A7%A3/

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 252

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report