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

Posted knowledge-is-power

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了输出redis cluster集群所有节点指定的参数的配置相关的知识,希望对你有一定的参考价值。

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

 

redis-trib.rb的输出

[[email protected] ~]$ 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/
//g`
    redis_port=`echo $i | awk -F: {print $2}|sed  s/
//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	 $x
            fi        
        done
        printf 
        echo
done

 

 

测试结果

[[email protected] ~]$ 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集群所有节点指定的参数的配置的主要内容,如果未能解决你的问题,请参考以下文章

怎样设置redis cluster的日志输出

redis之cluster(集群)

Redis-cluster 集群操作命令

Redis-Cluster操作命令大全

Redis3.0 cluster 配置

Redis Cluster集群