zoukankan      html  css  js  c++  java
  • redis集群的测试

    原文:http://blog.sina.com.cn/s/blog_53b45c4d0102wg10.html

        1、测试存取值

             客户端连接集群redis-cli需要带上 -c ,redis-cli -c -p 端口号

    1. [root@localhost redis01]# ./redis-cli -c -p 7001  
    2. 127.0.0.1:7001> set name andy  
    3. -> Redirected to slot [5798] located at 127.0.0.1:7002  
    4. OK  
    5. 127.0.0.1:7002> get name  
    6. "andy"  
    7. 127.0.0.1:7002>  

          根据redis-cluster的key值分配,name应该分配到节点7002[5461-10922]上,上面显示redis cluster自动从7001跳转到了7002节点。

           我们可以测试一下7006从节点获取name值

    [plain] view plain copy  在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis06]# ./redis-cli -c -p 7006  
    2. 127.0.0.1:7006> get name  
    3. -> Redirected to slot [5798] located at 127.0.0.1:7002  
    4. "andy"  
    5. 127.0.0.1:7002>   



            7006位7003的从节点,从上面也是自动跳转至7002获取值,这也是redis cluster的特点,它是去中心化,每个节点都是对等的,连接哪个节点都可以获取和设置数据。

    四、集群节点选举

             现在模拟将7002节点挂掉,按照redis-cluster原理会选举会将 7002的从节点7005选举为主节点。

            

    [plain] view plain copy  在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis-cluster]# ps -ef | grep redis  
    2. root       7950      1  0 12:50 ?        00:00:28 ./redis-server 127.0.0.1:7001 [cluster]  
    3. root       7952      1  0 12:50 ?        00:00:29 ./redis-server 127.0.0.1:7002 [cluster]  
    4. root       7956      1  0 12:50 ?        00:00:29 ./redis-server 127.0.0.1:7003 [cluster]  
    5. root       7960      1  0 12:50 ?        00:00:29 ./redis-server 127.0.0.1:7004 [cluster]  
    6. root       7964      1  0 12:50 ?        00:00:29 ./redis-server 127.0.0.1:7005 [cluster]  
    7. root       7966      1  0 12:50 ?        00:00:29 ./redis-server 127.0.0.1:7006 [cluster]  
    8. root      11346  10581  0 14:57 pts/2    00:00:00 grep --color=auto redis  
    9. [root@localhost redis-cluster]# kill 7952  

            在查看集群中的7002节点

    [plain] view plain copy  在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis-cluster]#   
    2. [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7002  
    3. [ERR] Sorry, can't connect to node 127.0.0.1:7002  
    4. [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7005  
    5. >>> Performing Cluster Check (using node 127.0.0.1:7005)  
    6. M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005  
    7.    slots:5461-10922 (5462 slots) master  
    8.    0 additional replica(s)  
    9. S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004  
    10.    slots: (0 slots) slave  
    11.    replicates dd19221c404fb2fc4da37229de56bab755c76f2b  
    12. M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003  
    13.    slots:10923-16383 (5461 slots) master  
    14.    1 additional replica(s)  
    15. M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001  
    16.    slots:0-5460 (5461 slots) master  
    17.    1 additional replica(s)  
    18. S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006  
    19.    slots: (0 slots) slave  
    20.    replicates f9886c71e98a53270f7fda961e1c5f730382d48f  
    21. [OK] All nodes agree about slots configuration.  
    22. >>> Check for open slots...  
    23. >>> Check slots coverage...  
    24. [OK] All 16384 slots covered.  
    25. [root@localhost redis-cluster]#   


          可以看到集群连接不了7002节点,而7005有原来的S转换为M节点,代替了原来的7002节点。我们可以获取name值:

    [plain] view plain copy  在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis01]# ./redis-cli -c -p 7001  
    2. 127.0.0.1:7001> get name  
    3. -> Redirected to slot [5798] located at 127.0.0.1:7005  
    4. "andy"  
    5. 127.0.0.1:7005>   
    6. 127.0.0.1:7005>   


       从7001节点连入,自动跳转到7005节点,并且获取name值。

        现在我们将7002节点恢复,看是否会自动加入集群中以及充当的M还是S节点。

          

    [plain] view plain copy  在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis-cluster]# cd redis02  
    2. [root@localhost redis02]# ./redis-server redis.conf   
    3. [root@localhost redis02]#   

         在check一下7002节点

    [plain] view plain copy  在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7002  
    2. >>> Performing Cluster Check (using node 127.0.0.1:7002)  
    3. S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002  
    4.    slots: (0 slots) slave  
    5.    replicates a5db243087d8bd423b9285fa8513eddee9bb59a6  
    6. M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003  
    7.    slots:10923-16383 (5461 slots) master  
    8.    1 additional replica(s)  
    9. M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005  
    10.    slots:5461-10922 (5462 slots) master  
    11.    1 additional replica(s)  
    12. S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004  
    13.    slots: (0 slots) slave  
    14.    replicates dd19221c404fb2fc4da37229de56bab755c76f2b  
    15. S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006  
    16.    slots: (0 slots) slave  
    17.    replicates f9886c71e98a53270f7fda961e1c5f730382d48f  
    18. M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001  
    19.    slots:0-5460 (5461 slots) master  
    20.    1 additional replica(s)  
    21. [OK] All nodes agree about slots configuration.  
    22. >>> Check for open slots...  
    23. >>> Check slots coverage...  
    24. [OK] All 16384 slots covered.  
    25. [root@localhost redis-cluster]#   

        可以看到7002节点变成了a5db243087d8bd423b9285fa8513eddee9bb59a6 7005的从节点。

  • 相关阅读:
    visual studio项目多级引用不拷贝dll的问题
    ef6 code first,对已有数据库如何执行迁移
    wsl 修改默认安装路径
    Windows docker镜像文件无法删除
    Docker镜像下载很慢,各种加速无效
    activemq整合springboot使用(个人微信小程序用)
    angular入门一之环境安装及项目创建
    jquery中attr()和prop()的区别
    IntelliJ IDEA部署web项目,Tomcat没有出现Artifacts
    IntelliJ IDEA:创建Java Web工程
  • 原文地址:https://www.cnblogs.com/shihaiming/p/5984006.html
Copyright © 2011-2022 走看看