首页 > 其他 > 详细

输出redis cluster集群所有节点指定的参数的配置

时间:2019-01-09 19:49:52      阅读:200      评论:0      收藏:0      [点我收藏+]

需要:实现类似redis-trib.rb call 命令的功能,输出redis cluster集群所有节点指定的参数的配置

 

redis-trib.rb的输出

[redis@lxd-vm3 ~]$ redis-trib.rb call 5.5.5.101:29001 config get *timeout*
/usr/local/ruby2.5.1/lib/ruby/gems/2.5.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated
>>> Calling CONFIG get *timeout*
5.5.5.101:29001: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"]
5.5.5.101:29004: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"]
5.5.5.102:29001: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"]
5.5.5.101:29003: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"]
5.5.5.102:29004: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"]
5.5.5.103:29003: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"]
5.5.5.102:29002: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"]
5.5.5.103:29002: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"]

 

编写脚本

ip_port=`redis-cli -h $1 -p $2 -a abc123 -c cluster nodes | awk {print $2} | awk -F@ {print $1}`

for i in $ip_port
do
    redis_ip=`echo $i | awk -F: {print $1}|sed  s/\r//g`
    redis_port=`echo $i | awk -F: {print $2}|sed  s/\r//g`
    redis_cmd="redis-cli -h $redis_ip -p $redis_port -a abc123 -c"
    echo -n "$redis_ip:$redis_port   "
    $redis_cmd  config get  $3 > config
    cat config | awk NR % 2 == 0 > even
    cat config | awk NR % 2 == 1 > odd
    paste -d : odd even > tmp.txt
    tail_line=$(cat tmp.txt|sed -n $p)
    printf 
    for x in `cat tmp.txt`
        do
            if [[ "$x" == "$tail_line" ]];then
               printf "%s" $x
            else
               printf %s\t $x
            fi        
        done
        printf 
        echo
done

 

 

测试结果

[redis@lxd-vm1 ~]$ sh get_redis_para.sh 5.5.5.101 29001 *timeout*
5.5.5.101:29001   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.101:29004   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.102:29001   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.101:29003   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.102:29004   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.103:29003   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.102:29002   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.103:29002   【timeout:0    repl-timeout:60    cluster-node-timeout:15000

 

输出redis cluster集群所有节点指定的参数的配置

原文:https://www.cnblogs.com/imdba/p/10246349.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!