redis创建集,redis-trib.rb命令详解

redis创建集,redis-trib.rb命令详解
redis-trib.rb是官⽅提供的Redis Cluster的管理⼯具,⽆需额外下载,默认位于源码包的src⽬录下,但因该⼯具是⽤ruby开发的,所以需要准备相关的依赖环境。
准备redis-trib.rb的运⾏环境
tar xvf ruby-2.5.
cd ruby-2.5.1/
./configure -prefix=/usr/local/ruby
make
make install
cd /usr/local/ruby/
cp bin/ruby /usr/local/bin
cp bin/gem /usr/local/bin
安装rubygem redis依赖
光纤电话机gem install -l redis-3.
redis-trib.rb⽀持的操作
# redis-trib.rb help
Usage: redis-trib <command> <options> <arguments ...>
create          host1:port1 ... hostN:portN
--replicas <arg>
check          host:port
info            host:port
fix            host:port
-
-timeout <arg>
reshard        host:port
--from <arg>
--to <arg>
--slots <arg>
--yes
--timeout <arg>
--pipeline <arg>
rebalance      host:port
--weight <arg>
--auto-weights
-
-use-empty-masters
--timeout <arg>
--simulate
--pipeline <arg>
--threshold <arg>
add-node        new_host:new_port existing_host:existing_port
--slave
--master-id <arg>
del-node        host:port node_id
set-timeout    host:port milliseconds
call            host:port command arg arg .. arg
import          host:port
--from <arg>
--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.
⽀持的操作如下:
1. create:创建集
2. check:检查集
3. info:查看集信息
4. fix:修复集
5. reshard:在线迁移slot
6. rebalance:平衡集节点slot数量
7. add-node:添加新节点
8. del-node:删除节点
9. set-timeout:设置节点的超时时间
10. call:在集所有节点上执⾏命令
创建集
redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384
--replicas参数指定集中每个主节点配备⼏个从节点,这⾥设置为1。
>>> Creating cluster
/usr/local/ruby/lib/ruby/gems/2.5.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated
>>> Performing hash slots allocation on
Using 3 masters:
127.0.0.1:6379
127.0.0.1:6380
127.0.0.1:6381
Adding replica 127.0.0.1:6383 to 127.0.0.1:6379
Adding replica 127.0.0.1:6384 to 127.0.0.1:6380
Adding replica 127.0.0.1:6382 to 127.0.0.1:6381
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: bc775f9c4dea40820b82c9451778b1fcd42f92bc 127.0.0.1:6379
slots:0-5460 (5461 slots) master
M: 3b27d00d13706a032a92ff6b0a914af272dcaaf2 127.0.0.1:6380
slots:5461-10922 (5462 slots) master
M: d874f003257f1fb036bbd856ca605172a1741232 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
S: 648eb314863b82aaa676380be7db2ec307f5547d 127.0.0.1:6382
replicates bc775f9c4dea40820b82c9451778b1fcd42f92bc
S: 65a6efb441ac44c348f7da8c62e26b888cda7c48 127.0.0.1:6383
replicates 3b27d00d13706a032a92ff6b0a914af272dcaaf2
S: 57bda956485109552547aef6c77fba43d2124abf 127.0.0.1:6384
replicates d874f003257f1fb036bbd856ca605172a1741232
Can I set the above configuration? (type 'yes' to accept): yes
来电显示电话机
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster
>>> Performing Cluster Check (using node 127.0.0.1:6379)
M: bc775f9c4dea40820b82c9451778b1fcd42f92bc 127.0.0.1:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 648eb314863b82aaa676380be7db2ec307f5547d 127.0.0.1:6382
slots: (0 slots) slave扫频信号源
replicates bc775f9c4dea40820b82c9451778b1fcd42f92bc
M: 3b27d00d13706a032a92ff6b0a914af272dcaaf2 127.0.0.1:6380
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 57bda956485109552547aef6c77fba43d2124abf 127.0.0.1:6384
slots: (0 slots) slave
replicates d874f003257f1fb036bbd856ca605172a1741232
S: 65a6efb441ac44c348f7da8c62e26b888cda7c48 127.0.0.1:6383
slots: (0 slots) slave
疲劳驾驶预警系统
replicates 3b27d00d13706a032a92ff6b0a914af272dcaaf2
M: d874f003257f1fb036bbd856ca605172a1741232 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for
>>> Check
[OK] All 16384 slots covered.
16384个槽全部被分配,集创建成功。注意:给redis-trib.rb的节点地址必须是不包含任何槽/数据的节点,否则会拒绝创建集。
>>> Creating cluster
/
usr/local/ruby/lib/ruby/gems/2.5.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated
[ERR] Node 127.0.0.1:6379 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
关于主从节点的选择及槽的分配,其算法如下:
1> 把节点按照host分类,这样保证master节点能分配到更多的主机中。
2> 遍历host列表,从每个host列表中弹出⼀个节点,放⼊interleaved数组。直到所有的节点都弹出为⽌。
3> 将interleaved数组中前master个数量的节点保存到masters数组中。
4> 计算每个master节点负责的slot数量,16384除以master数量取整,这⾥记为N。
5> 遍历masters数组,每个master分配N个slot,最后⼀个master,分配剩下的slot。
6> 接下来为master分配slave,分配算法会尽量保证master和slave节点不在同⼀台主机上。对于分配
完指定slave数量的节点,还有多余的节点,也会为这些节点寻master。分配算法会遍历两次masters数组。
7> 第⼀次遍历master数组,在余下的节点列表到replicas数量个slave。每个slave为第⼀个和master节点host不⼀样的节点,如果没有不⼀样的节点,则直接取出余下列表的第⼀个节点。
8> 第⼆次遍历是分配节点数除以replicas不为整数⽽多出的⼀部分节点。
检查集状态
redis-trib.rb check 127.0.0.1:6379
指定任意⼀个节点即可。
/usr/local/ruby/lib/ruby/gems/2.5.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated
>>> Performing Cluster Check (using node 127.0.0.1:6379)
M: bc775f9c4dea40820b82c9451778b1fcd42f92bc 127.0.0.1:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 648eb314863b82aaa676380be7db2ec307f5547d 127.0.0.1:6382
slots: (0 slots) slave
replicates bc775f9c4dea40820b82c9451778b1fcd42f92bc
M: 3b27d00d13706a032a92ff6b0a914af272dcaaf2 127.0.0.1:6380
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 57bda956485109552547aef6c77fba43d2124abf 127.0.0.1:6384
slots: (0 slots) slave
replicates d874f003257f1fb036bbd856ca605172a1741232
S: 65a6efb441ac44c348f7da8c62e26b888cda7c48 127.0.0.1:6383
slots: (0 slots) slave
replicates 3b27d00d13706a032a92ff6b0a914af272dcaaf2
M: d874f003257f1fb036bbd856ca605172a1741232 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for
>>> Check
[OK] All 16384 slots covered.
查看集信息
redis-trib.rb info 127.0.0.1:6383
/usr/local/ruby/lib/ruby/gems/2.5.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated 127.0.0.1:6380 () -> 0 keys | 5462 slots | 1 slaves.
127.0.0.1:6381 () -> 1 keys | 5461 slots | 1 slaves.
127.0.0.1:6379 () -> 0 keys | 5461 slots | 1 slaves.
[OK] 1 keys in 3 masters.
0.00 keys per slot on average.
修复集
⽬前fix命令能修复两种异常,
1. 节点中存在处于迁移中(importing或migrating状态)的slot。
洗水2. 节点中存在未分配的slot。
检修电源箱
其它异常不能通过fix命令修复。
[root@slowtech conf]# redis-trib.rb fix 127.0.0.1:6379
/usr/local/ruby/lib/ruby/gems/2.5.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated >>> Performing Cluster Check (using node 127.0.0.1:6379)
S: d826c5fd98efa8a17a880e9a90a25f06c88e6ae9 127.0.0.1:6379
slots: (0 slots) slave
replicates a8b3d0f9b12d63dab3b7337d602245d96dd55844
S: 55c05d5b0dfea0d52f88548717ddf24975268de6 127.0.0.1:6383
slots: (0 slots) slave
replicates a8b3d0f9b12d63dab3b7337d602245d96dd55844
M: f413fb7e6460308b17cdb71442798e1341b56cbc 127.0.0.1:6381
slots:50-16383 (16334 slots) master
2 additional replica(s)
S: beba753c5a63607fa66d9ec7427ed9a511ea136e 127.0.0.1:6382
slots: (0 slots) slave
replicates f413fb7e6460308b17cdb71442798e1341b56cbc
S: 83797d518e56c235272402611477f576973e9d34 127.0.0.1:6384
slots: (0 slots) slave
replicates f413fb7e6460308b17cdb71442798e1341b56cbc
M: a8b3d0f9b12d63dab3b7337d602245d96dd55844 127.0.0.1:6380
slots:0-49 (50 slots) master
2 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for
>>> Check
[OK] All 16384 slots covered.
在线迁移slot
交互环境中使⽤
如,

本文发布于:2024-09-22 18:25:42,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/3/209447.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:节点   集群   分配   数量   依赖   电话机   数组   创建
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议