码迷,mamicode.com
首页 > 其他好文 > 详细

直观获取redis cluster 主从关系

时间:2018-12-13 19:16:33      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:sub   ted   需求   clust   color   sla   方法   ++   slaves   

 

需求:还是redis-trib.rb脚本获取的信息不足或者太繁杂,这里给出更加直观的一种方法,

说明:已在4.x版本测试通过,3.x不可用。

 

原生的输出

[redis@lxd-vm3 redis]$ redis-trib.rb info 5.5.5.101:29001
5.5.5.101:29001 (1adfa7f3...) -> 2599 keys | 4596 slots | 1 slaves.
5.5.5.101:29004 (32fc101a...) -> 4181 keys | 3595 slots | 1 slaves.
5.5.5.102:29002 (76a8592d...) -> 5041 keys | 4096 slots | 1 slaves.
5.5.5.103:29003 (31ba5414...) -> 5011 keys | 4097 slots | 1 slaves.
[OK] 16832 keys in 4 masters.
1.03 keys per slot on average.
[redis@lxd-vm3 redis]$ redis-cli -h 5.5.5.101 -p 29001 -c -a abc123 cluster nodes
6178b88137d2dd621f5445f13faa9936b300333a 5.5.5.102:29004@39004 slave 32fc101a2920c98f279a31292ace9ff3aeaa35a3 0 1544694513000 16 connected
32fc101a2920c98f279a31292ace9ff3aeaa35a3 5.5.5.101:29004@39004 master - 0 1544694515000 16 connected 824-1382 2200-2499 3001 5462-6828 10923-12290
c27b170791473946085c85c6fa7c163b24efe6e0 5.5.5.102:29001@39001 slave 1adfa7f3e80c47d5bd3072e9d07c1b2bcc8ef4a1 0 1544694514000 24 connected
cb88f415e0dc61616e1ed861a00aa8416dd6dd3f 5.5.5.101:29003@39003 slave 31ba5414196da8b6ed8e0640472d3870d5f6f591 0 1544694515665 20 connected
76a8592df53de4d45fb66fa8e48ef9fb0991ae14 5.5.5.102:29002@39002 master - 0 1544694514000 27 connected 821-823 1383-2199 7647-10922
1adfa7f3e80c47d5bd3072e9d07c1b2bcc8ef4a1 5.5.5.101:29001@39001 myself,master - 0 1544694513000 24 connected 2500-3000 3002-3299 3301-5461 6829-7646 12291-13108
723bfff7241ab8abfc46eeea280d673f84311056 5.5.5.103:29002@39002 slave 76a8592df53de4d45fb66fa8e48ef9fb0991ae14 0 1544694514663 27 connected
31ba5414196da8b6ed8e0640472d3870d5f6f591 5.5.5.103:29003@39003 master - 0 1544694513656 20 connected 0-820 3300 13109-16383
[redis@lxd-vm3 redis]$ 

 

编写脚本直观获取

[redis@lxd-vm3 redis]$ cat get_master_slave.sh 
cmd="redis-cli -c -h $1 -p $2"
master_id=(`$cmd cluster nodes | grep master | awk {print $1}`)
master_ip_port=(`$cmd cluster nodes | grep master | awk $2 ~ /@.*/{gsub("@.*","",$2);print $2}`)

len=${#master_id[@]}
for ((i=0;i<=$len-1;i++));
do
echo -n "${master_ip_port[$i]} ->  "
echo `$cmd cluster slaves ${master_id[$i]} | awk $2 ~ /@.*/{gsub("@.*","",$2);print $2}` 
done
[redis@lxd-vm3 redis]$ 
[redis@lxd-vm3 redis]$ sh get_master_slave.sh 5.5.5.101 29001
5.5.5.101:29004 ->  5.5.5.102:29004
5.5.5.102:29002 ->  5.5.5.103:29002
5.5.5.101:29001 ->  5.5.5.102:29001
5.5.5.103:29003 ->  5.5.5.101:29003
[redis@lxd-vm3 redis]$ 

 

直观获取redis cluster 主从关系

标签:sub   ted   需求   clust   color   sla   方法   ++   slaves   

原文地址:https://www.cnblogs.com/imdba/p/10115447.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!