In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Detailed explanation of redis-trib.rb command
Redis-trib.rb is an official management tool for Redis Cluster, which is located in the src directory of the source package by default without additional download, but because the tool is developed in ruby, you need to prepare the relevant dependent environment.
Official website: https://redis.io/documentation
Chinese official website: http://www.redis.cn/documentation.html
1 Operation supported by redis-trib.rb [root@node1 src] #. / redis-trib.rb helpUsage: redis-trib create host1:port1... HostN:portN-replicas check host:port info host:port fix host:port-timeout reshard host:port-from-to-slots-yes -- timeout-- pipeline rebalance host:port-- weight-- auto-weights-- use-empty-masters-- timeout-- simulate-- pipeline-- threshold add-node New_host:new_port existing_host:existing_port-slave-master-id del-node host:port node_id set-timeout host:port milliseconds call host:port command arg arg.. Arg import host:port-from-copy-replace help (show this help) For check, fix, reshard, del-node Set-timeout you can specify the host and port of any working node in the cluster. [root@node1 src] # supported operations are as follows: create: create cluster check: check cluster info: view cluster information fix: repair cluster reshard: online migration slotrebalance: balance the number of cluster nodes slot add-node: add new nodes to the cluster del-node: remove nodes from the cluster set-timeout: set the timeout for heartbeat connections between cluster nodes Call: execute the command import on all nodes of the cluster: import external redis data into the cluster
For check,fix,reshard,del-node,set-timeout, you can specify the host and port of any worker node in the cluster.
2 create a cluster
Users do not need to specify which node is master and which is slave, because the internal algorithm of redis can help us to create a master node and then specify a slave node.
Create
-- replicas # optional parameter, replicas indicates how many slave are required for each master.
Only the way the master node is created. / redis-trib.rb create 192.168.1.101Vl7000 192.168.1.102VRV 7000 192.168.1.103Vl7000192.168.1.104Vl7000192.168.105VRV 7000 192.168.1.106VR7000 using-- replicas 1 to create each master with one slave instruction. / redis-trib.rb create-- replicas 1 192.168.1.101Vl7000 192.168.1.102: 7000 192.168.1.103:7000 192.168.1.104:7000 192.168.1.105:7000 192.168.1.106:7000
All 16384 slots are allocated and the cluster is created successfully. Note: the node address given to redis-trib.rb must be a node that does not contain any slots / data, otherwise the creation of a cluster will be refused.
With regard to the selection of master-slave nodes and slot allocation, the algorithm is as follows:
Classify nodes according to host to ensure that master nodes can be allocated to more hosts.
Iterate through the host list, pop a node from each host list and put it in the interleaved array. Until all the nodes pop up.
Save the first number of master nodes in the interleaved array to the masters array.
Calculate the number of slot responsible for each master node, 16384 divided by the number of master rounded, which is marked N here.
Iterate through the masters array, allocating N slot for each master, the last master, and allocating the remaining slot.
Next, assign slave to the master, and the allocation algorithm tries to ensure that the master and slave nodes are not on the same host. For the nodes that have been allocated the specified number of slave, and there are extra nodes, the master will also be looked for for these nodes. The allocation algorithm iterates through the masters array twice.
Iterate through the master array for the first time and find the number of replicas slave in the remaining node list. Each slave is the first node that is different from the master node host. If there is no different node, the first node in the remaining list is directly taken out.
The second traversal is to allocate the number of nodes divided by the number of replicas which is not an integer.
3 check the cluster: check
You can specify any node.
. / redis-trib.rb check 192.168.1.101:7000
Display:
[root@NUC-2 src] #. / redis-trib.rb check 192.168.1.101master 7000 > Performing Cluster Check (using node 192.168.1.101Vera 7000) S: afaa82815a7fc2d0e19ffa664677dde03aa8ab36 192.168.1.101Vera 7000 slots: (0 slots) slave replicates 845674c71b1f43f9297501903e616140b2a0a1f6M: b7cada75939d960f8ca98aad875b8f2e49020b19 192.168.1.102 master 7000 master 1 additional replica (s) M: f1946135289c8c76bb9817213cbb1730d9a0b052 192.168.1.103 master 7000 slots:10923-16383 (5461 slots) master 1 additional replica (s) S: 9f9a36f2da46bd18f9df785900b5a8e3c53b5ca3 192.168.1.106 slots 7000 slots: (0 slots) slave replicates b7cada75939d960f8ca98aad875b8f2e49020b19M: 845674c71b1f43f9297501903e616140b2a0a1f6 192.168.1.105 slots 7000 slots:0-5460 (5461 slots) master 1 additional replica (s) S: 15fc1bd754a2e02ec571e23c7d81a80c7322a100 192.168.1.104 slots: (0 slots) slave replicates f1946135289c8c76bb9817213cbb1730d9a0b052 [OK] All nodes agree about slots configuration. > > Check for open slots... > > Check slots coverage... [OK] All 16384 slots covered. [root@NUC -2 src] # 4 View cluster information: Info[ root @ NUC-2 src] #. / redis-trib.rb info 192.168.20.61Vera 7000192.168.20.62V7 000 (b7cada75...)-> 2 keys | 5462 slots | 1 slaves.192.168.20.63:7000 (f1946135...)-> 2 keys | 5461 slots | 1 slaves.192.168.20.65:7000 (845674c7...)-> 4 keys | 5461 slots | 1 slaves . [OK] 8 keys in 3 masters.0.00 keys per slot on average. [root @ NUC-2 src] # 5 repair the cluster
Currently, the fix command can fix two kinds of exceptions:
There is a slot in the node that is in the state of migration (importing or migrating). There is an unassigned slot in the node.
Other exceptions cannot be fixed by the fix command. [root@NUC-2 src] #. / redis-trib.rb fix 192.168.20.61 master 7000 > Performing Cluster Check (using node 192.168.20.61Vera 7000) S: afaa82815a7fc2d0e19ffa664677dde03aa8ab36 192.168.20.61 master 7000 slots: (0 slots) slave replicates 845674c71b1f43f9297501903e616140b2a0a1f6M: b7cada75939d960f8ca98aad875b8f2e49020b19 192.168.20.62 master 7000 additional replica (s) M: f1946135289c8c76bb9817213cbb1730d9a0b052 192.168.20.63 slots:10923 7000 (5461 slots) master 1 additional replica (s) S: 9f9a36f2da46bd18f9df785900b5a8e3c53b5ca3 192.168.20.66 slots 7000 slots: (0 slots) slave replicates b7cada75939d960f8ca98aad875b8f2e49020b19M: 845674c71b1f43f9297501903e616140b2a0a1f6 192.168.20.65 Vol 7000 slots:0-5460 (5461 slots) master 1 additional replica (s) S: 15fc1bd754a2e02ec571e23c7d81a80c7322a100 192.168.20.64 slots 7000 slots: (0 slots) slave replicates f1946135289c8c76bb9817213cbb1730d9a0b052 [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered. [root@NUC -2 src] # 6 online migration: slot format: redis-trib.rb reshardhost:port-- from-- to-- slots-- yes-- timeout-- pipeline option: reshardhost:port: required parameter The address of any node in the cluster is used to obtain the information of the whole cluster. -- from: to which source nodes need to migrate slot, you can complete the migration from multiple source nodes separated by commas. You can pass the node id of the node or-- from all directly, so that the source node is all the nodes of the cluster. If this parameter is not passed, the user will be prompted for input during the migration process. -- to: slot needs the node id of the destination node to be migrated. Only one node id can be entered in the destination node. If this parameter is not passed, the user will be prompted for input during the migration. -- slots: the number of slot to be migrated. If this parameter is not passed, the user will be prompted for input during the migration process. -- yes: set this parameter to prompt the user to enter yes for confirmation before executing reshard when printing and executing the reshard plan. -- timeout: controls the timeout for each migrate operation. The default is 60000 milliseconds. -- pipeline: defines the number of key fetched by the cluster getkeysinslot command at a time. If not passed, the default value is 10. Example:. / redis-trib.rb reshard-- from all-- to 845674c71b1f43f9297501903e616140b2a0a1f6-- slots 11 7 balance the number of cluster nodes slot option: rebalance host:port-- weight-- auto-weights-- use-empty-masters-- timeout-- simulate-- pipeline -- threshold indicates that rebalancehost:port: this is a required parameter 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-trib.rb rebalance-- weight 845674c71b1f43f9297501903e616140b2a0a1f6=3-- weight b7cada75939d960f8ca98aad875b8f2e49020b19=2-- use-empty-masters 192.168.20.61 use-empty-masters 7000 to 7000 added a master node. / from 192.168.1.107000 to 7000 192.168.1.108 weight b7cada75939d960f8ca98aad875b8f2e49020b19=2 700mm was added successfully, but no slot was specified, so the slot node must be migrated. / redis-trib.rb reshard 192.168.1.108 to 700cycles hint 1: How many slots do you want to move? To balance the number of slot managed by each master, enter the number of 16384/master. If it's 4 here, then it's 16384. 4 = 4096. Enter 409 hint two: What is the receiving node ID? (what is the node ID accepted) ID# hint 3 for 890d2c8d989cce50e5fa48e37cd35738887f3f7d # 107: Please enter all the source node IDs. Type 'all' to use all the nodes as source nodes for the hash slots. Type 'done' once you entered all the source nodes IDs. (from which node do you want to get the lost? ) if you are not going to take a specified number of hash slots from a specific node, you can enter all or enter a node's node ID# to check whether it is successful. / redis-trib.rb check 192.168.1.108redis-trib.rb check 7000 add a new node
Format:
Redis-trib add-node new_host:new_port existing_host:existing_port-slave-master-id
Among them
New_host:new_port: the node to be added must make sure that it is empty or is not in another cluster. Otherwise, the following error is prompted.
[ERR] Node 192.168.1.101:7000 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
Therefore, it is recommended online that you use redis-trib.rb to add a new node because it checks the status of the new node. If you manually use the cluster meet command to join nodes that already exist in other clusters, it will cause the clusters of the joined nodes to merge into the existing clusters, resulting in data loss and confusion, with serious consequences and careful online operation.
Existing_host:existing_port: the address of any node in the cluster.
If you are adding a primary node, you only need to specify the addresses of the source and destination nodes.
Redis-trib.rb add-node 192.168.1.101:7000 127.0.0.1:6384
If you add a slave node, the syntax is as follows
Redis-trib.rb add-node-- slave-- master-id f413fb7e6460308b17cdb71442798e1341b56cbc 192.168.1.101 master-id f413fb7e6460308b17cdb71442798e1341b56cbc 7000127.0.0.1 master-id f413fb7e6460308b17cdb71442798e1341b56cbc 6384
Note:-- slave and-- master-id must be written in front. The same parameters, if written as follows, will prompt an error.
# redis-trib.rb add-node 192.168.1.101 master-id f413fb7e6460308b17cdb71442798e1341b56cbc 7000 127.0.0.1 master-id f413fb7e6460308b17cdb71442798e1341b56cbc [ERR] Wrong number of arguments for specified sub command
Add a slave node, but do not set-- master-id, and the master node will be randomly selected.
The slave node automatically matches the master node. / redis-trib.rb add-node-- specify the master node when the slave node is added to the slave 127.0.0.1 7007 127.0.1 7000. . / redis-trib.rb add-node-- slave-- master-id 890d2c8d989cce50e5fa48e37cd35738887f3f7d 192.168.66.3 master-id 890d2c8d989cce50e5fa48e37cd35738887f3f7d 7008 192.168.66.2 master-id 890d2c8d989cce50e5fa48e37cd35738887f3f7d 7000 delete node format redis-trib.rb del-node host:port node_id parameter: del-node: delete node instruction; host:port: get cluster information from this node; node_id: node id to be deleted.
Before deleting a node, its corresponding slot must be empty, so it must be migrated out using redis-trib.rb reshard before the node deletion action can be performed.
It is important to note that if the slot of a node is completely migrated, its corresponding slave will also be updated to point to the target node of the migration.
. / redis-trib.rb del-node 192.168.66.2 redis-trib.rb set-timeout host:port milliseconds 7000 d5f6d1d17426bd564a6e309f32d0f5b96962fe53 sets the timeout of the node
In fact, it is to modify the cluster-node-timeout parameters of each node of the cluster in batches.
# redis-trib.rb set-timeout 192.168.1.1017000 20000/usr/local/ruby/lib/ruby/gems/2.5.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant:: Fixnum is deprecated > > Reconfiguring node timeout in every cluster node...*** New timeout set for 192.168.1.101 redis-trib.rb set-timeout 7000mm * New timeout set for 192.168.1.102 * New timeout set for 192.168.1 .103: 7000mm * New timeout set for 192.168.1.104 * New timeout set for 192.168.1.105 * New timeout set for 192.168.1.106Rd 7000 > New node timeout set. 6 OK, 0 ERR. Import external redis data into cluster redis-trib.rb import-- from 127.0.0.1 from 6378 127.0.1
The internal processing flow is as follows:
1 > load the cluster information by load_cluster_info_from_node method, and check whether the cluster is healthy by check_cluster method.
2 > Connect the external redis node. If the external node has cluster_enabled enabled, it will prompt an error ([ERR] The source node should not be a cluster node.)
3 > traverse the external nodes through the scan command and get 1000 pieces of data at a time.
4 > iterate through these key to calculate the slot corresponding to key.
5 > execute the migrate command. The source node is the external node and the destination node is the corresponding node of the cluster slot. If the-- copy parameter is set, the copy parameter is passed, which retains the key of the source node. If-- replace is set, the replace parameter is passed. If a key with the same name exists in the target node, its value is overwritten. Two parameters can be specified at the same time.
6 > execute the scan command until you have traversed all the key.
7 > Migration completed.
Downtime situation
When a slave node dies, it has little effect on the redis cluster, which means that the master node corresponding to the slave node is missing a backup.
When a master node dies, redis selects one of the multiple slave nodes of the master node to act as the master and attach the previous
The slave node adjustment of the master node is attached to the new master. If the new master also dies and he doesn't have a slave node, then the cluster is really dead.
The replicas parameter is specified when the cluster is created.
When using the-- replicas 1 parameter, if the number of nodes is less than six.
Error
* * ERROR: Invalid configuration for cluster creation.*** Redis Cluster requires at least 3 master nodes.*** This is not possible with 5 nodes and 1 replicas per node.*** At least 6 nodes are required.
When using the-- replicas 1 parameter, if the number of nodes is greater than six and is singular.
This will cause a master to have two salve
Referenc
Https://www.cnblogs.com/ivictor/p/9768010.html
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: 0
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.