• 另外一种获取redis cluster主从关系和slot分布的方法


    条条大路通罗马,通过最近学习redis cluster 观察其输出,发现了另外一种获取master-slave关系的方法。

    [redis@lxd-vm1 ~]$ cat get_master_slave2.sh 
    redis-cli -h $1 -p $2 -a abc123 -c cluster nodes > cluster_nodes.txt
    echo "master to slave info..."
    cat cluster_nodes.txt | awk '/master/{print $1,$2}' | sort -nk2 -t ':'  > master.txt
    cat cluster_nodes.txt | awk '/slave/{print $2,$4}' | sort -nk1 -t ':'  > slave.txt
    cat master.txt | while read m
    do 
        master_ip_port=`echo $m | awk '{print $2}'`
        master_tag=`echo $m | awk '{print $1}'`
        cat slave.txt | while read s
        do
            slave_ip_port=`echo $s | awk '{print $1}'`
            slave_tag=`echo $s | awk '{print $2}'`
            if [[ ${master_tag} == ${slave_tag} ]];then
            echo "${master_ip_port}->${slave_ip_port}"
            fi
        done
    done
    
    echo ""
    echo "master slots info...."
    cat cluster_nodes.txt |grep master | uniq | sort -nk9 > ./all
    cat all | awk '{print $2}' > 222
    cat all | awk -F " "  '{for (i=9;i<=NF;i++)printf("%s ", "["$i"]");print " "}' > 999
    paste -d "#" 222 999 > 2_9.txt
    cat 2_9.txt
    [redis@lxd-vm1 ~]$ sh get_master_slave2.sh 5.5.5.101 29001
    master to slave info...
    5.5.5.101:29001@39001->5.5.5.102:29001@39001
    5.5.5.102:29002@39002->5.5.5.103:29002@39002
    5.5.5.103:29003@39003->5.5.5.101:29003@39003
    5.5.5.101:29004@39004->5.5.5.102:29004@39004
    
    master slots info....
    5.5.5.103:29003@39003#[0-820] [3300] [13109-16383]  
    5.5.5.102:29002@39002#[821-823] [1383-2199] [7647-10922]  
    5.5.5.101:29004@39004#[824-1382] [2200-2499] [3001] [5462-6828] [10923-12290]  
    5.5.5.101:29001@39001#[2500-3000] [3002-3299] [3301-5461] [6829-7646] [12291-13108]  
    [redis@lxd-vm1 ~]$ 
  • 相关阅读:
    CentOS 7搭建SVN服务器
    CentOS 配置MySQL允许远程登录
    使用nginx实现基于tcp协议的https协议多域名指向的分别转发功能
    centos7 设置内核启动顺序
    nginx 针对特定地区的ip进行规则匹配
    【转】golang 交叉编译
    linux修改用户id,组id
    etcd 增减节点
    [转]etcd 启用 https
    windows 多网卡路由设置
  • 原文地址:https://www.cnblogs.com/imdba/p/10115578.html
Copyright © 2020-2023  润新知