zoukankan      html  css  js  c++  java
  • redis6 redis-cli cluster的使用总结

    个人学习笔记,谢绝转载!!!

    原文:https://www.cnblogs.com/wshenjin/p/15466843.html


    --cluster help

    redis-cli --cluster help
    Cluster Manager Commands:
      create         host1:port1 ... hostN:portN   #创建集群
                     --cluster-replicas <arg>      #从节点个数
      check          host:port                     #检查集群
                     --cluster-search-multiple-owners #检查是否有槽同时被分配给了多个节点
      info           host:port                     #查看集群状态
      fix            host:port                     #修复集群
                     --cluster-search-multiple-owners #修复槽的重复分配问题
      reshard        host:port                     #指定集群的任意一节点进行迁移slot,重新分slots
                     --cluster-from <arg>          #需要从哪些源节点上迁移slot,可以逗号隔开从多个源节点完成迁移,参数是nodeid
                                                   #还可以直接传递--from all,这样源节点就是集群的所有节点,不传递该参数,则会在迁移过程中提示用户输入
                     --cluster-to <arg>            #slot需要迁移的目的节点nodeid,目的节点只能填写一个,不传递该参数,则会在迁移过程中提示用户输入
                     --cluster-slots <arg>         #需要迁移的slot数量,不传递该参数的话,则会在迁移过程中提示用户输入。
                     --cluster-yes                 #指定迁移时的确认输入
                     --cluster-timeout <arg>       #设置migrate命令的超时时间
                     --cluster-pipeline <arg>      #定义cluster getkeysinslot命令一次取出的key数量,不传的话使用默认值为10
                     --cluster-replace             #是否直接replace到目标节点
      rebalance      host:port                                      #指定集群的任意一节点进行平衡集群节点slot数量 
                     --cluster-weight <node1=w1...nodeN=wN>         #指定集群节点的权重
                     --cluster-use-empty-masters                    #设置可以让没有分配slot的主节点参与,默认不允许
                     --cluster-timeout <arg>                        #设置migrate命令的超时时间
                     --cluster-simulate                             #模拟rebalance操作,不会真正执行迁移操作
                     --cluster-pipeline <arg>                       #定义cluster getkeysinslot命令一次取出的key数量,默认值为10
                     --cluster-threshold <arg>                      #迁移的slot阈值超过threshold,执行rebalance操作
                     --cluster-replace                              #是否直接replace到目标节点
      add-node       new_host:new_port existing_host:existing_port  #添加节点,把新节点加入到指定的集群,默认添加主节点
                     --cluster-slave                                #新节点作为从节点,默认随机一个主节点
                     --cluster-master-id <arg>                      #给新节点指定主节点
      del-node       host:port node_id                              #删除给定的一个节点,成功后关闭该节点服务
      call           host:port command arg arg .. arg               #在集群的所有节点执行相关命令
      set-timeout    host:port milliseconds                         #设置cluster-node-timeout
      import         host:port                                      #将外部redis数据导入集群
                     --cluster-from <arg>                           #将指定实例的数据导入到集群
                     --cluster-copy                                 #migrate时指定copy
                     --cluster-replace                              #migrate时指定replace
      help           
    
    For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.
    

    集群操作

    创建一个三主节点不带从节点的集群:

    shell# redis6-cli --user admin --pass *** --cluster create 
           192.168.1.21:6379 192.168.1.22:6379 192.168.1.23:6379  
    

    创建一个三节点带从节点的集群:

    shell# redis6-cli --user admin --pass *** --cluster create --cluster-replicas 1 
           192.168.1.21:6379 192.168.1.22:6379 192.168.1.23:6379 
           192.168.1.24:6379 192.168.1.25:6379 192.168.1.26:6379
    
    • --cluster-replicas N,N表示每个主节点需要N个从节点

    添加主节点:

    add-node new_host:new_port existing_host:existing_port

    shell# redis-cli -h 192.168.1.21 -p 6379 --user admin --pass *** --cluster add-node 
           192.168.1.24:6379 192.168.1.21:6379 
    

    给主节点添加从节点:

    add-node new_host:new_port existing_host:existing_port --cluster-slave --cluster-master-id

    shell# redis-cli -h 192.168.1.21 -p 6379 --user admin --pass *** --cluster add-node 
           192.168.1.24:6379 192.168.1.21:6379 --cluster-slave --cluster-master-id  
           035f9cb03ead48c7a35a6247834d397be7442b71 
    
    • 不指定 --cluster-master-id参数,新从节点任意分配给一个主节点

    删除节点:

    可以直接删除从节点,已经分配slot的主节点无法删除

    shell# redis-cli --user admin --pass *** --cluster del-node 192.168.1.21:6379  
           2afbf631cb81139c7cce6fc4b06263c697ff31ea
    
    shell# redis-cli --user admin --pass *** --cluster del-node 192.168.1.21:6379  
           f15857c88d90af3885b8be8edfc7a8905b28334a
    >>> Removing node f15857c88d90af3885b8be8edfc7a8905b28334a from cluster 192.168.1.21:6379
    [ERR] Node 192.168.1.23:6379 is not empty! Reshard data away and try again.
    

    查看集群信息:

    shell# redis-cli --user admin --pass *** --cluster info 192.168.1.21:6379
    

    集群检查:

    shell# redis-cli --user admin --pass *** --cluster check 192.168.1.21:6379
    
    • --cluster-search-multiple-owners , 检查是否有槽同时被分配给了多个节点

    集群修复:

    shell# redis-cli --user admin --pass *** --cluster fix 192.168.1.21:6379
    
    • --cluster-search-multiple-owners , 修复槽的重复分配问题
    • --cluster-fix-with-unreachable-masters

    设置集群超时

    shell# redis-cli --user admin --pass *** --cluster set-timeout 192.168.1.21:6379 10000
    

    集群中执行命令:

    shell# redis-cli --user admin --pass *** --cluster call 192.168.1.21:6379 config get maxmemory 
    
    • --cluster-only-masters

    • --cluster-only-replicas

    集群备份:

    shell# redis-cli --user admin --pass *** --cluster backup 192.168.1.21:6379 /data/backup/
    
    • 怎么从备份文件中恢复????

    slot操作

    手动迁移slot:

    shell# redis-cli --user admin --pass *** --cluster reshard  192.168.1.21:6379 
           --cluster-from 035f9cb03ead48c7a35a6247834d397be7442b71 
           --cluster-to 6120f24e60e4f8a11df8fc7e9a50c2a3711abf5f 
           --cluster-slots 100 --cluster-yes --cluster-pipeline 10 --cluster-replace
    
    • --cluster-from , 需要从哪些源节点上迁移slot,可以逗号隔开从多个源节点完成迁移,传递的是节点的nodeid。可以直接传递--from all,这样源节点就是集群的所有节点,不传递该参数的话,则会在迁移过程中提示用户输入。
    • --cluster-to , slot需要迁移的目的节点的node id,目的节点只能填写一个,不传递该参数的话,则会在迁移过程中提示用户输入。
    • --cluster-slots , 需要迁移的slot数量,不传递该参数的话,则会在迁移过程中提示用户输入。
    • --cluster-yes , 指定迁移时的确认输入
    • --cluster-timeout , 设置migrate命令的超时时间
    • --cluster-pipeline , 定义cluster getkeysinslot命令一次取出的key数量,不传的话使用默认值为10
    • --cluster-replace , 是否直接replace到目标节点

    平衡各个节点的slot数量:

    shell# redis-cli --user admin --pass *** --cluster rebalance 192.168.1.21:6379
    
    • --cluster-weight <node1=w1...nodeN=wN> , 指定集群节点的权重
    • --cluster-use-empty-masters , 设置可以让没有分配slot的主节点参与,默认不允许
    • --cluster-timeout , 设置migrate命令的超时时间
    • -cluster-simulate , 模拟rebalance操作,不会真正执行迁移操作
    • --cluster-pipeline , 定义cluster getkeysinslot命令一次取出的key数量,默认值为10
    • --cluster-threshold , 迁移的slot阈值超过threshold,执行rebalance操作
    • --cluster-replace , 是否直接replace到目标节点

    从其他实例导数据到集群:

    shell# redis-cli --user admin --pass *** --cluster import 192.168.1.21:6379 
           --cluster-from 127.0.0.1:6004 --cluster-from-user admin --cluster-from-pass *** --cluster-replace
    
    • --cluster-from ,将指定实例的数据导入到集群
    • --cluster-from-user , 用户
    • --cluster-from-pass , 密码
    • --cluster-copy ,migrate时指定copy
    • --cluster-replace ,migrate时指定replace
  • 相关阅读:
    53、Gif 控件GifView 的使用,播放gif图片
    52、图片缩放库 PhotoView
    51、自定义View基础和原理
    Adapter适配器 final int Id 导致选中的Item不在当前界面
    Linux目录结构
    Linux包管理工具分析
    Linux 软件包安装管理
    MySQL配置详解
    MySQL 5.5.x配置文件详解
    Linux Apache2 配置介绍
  • 原文地址:https://www.cnblogs.com/wshenjin/p/15466843.html
Copyright © 2011-2022 走看看