Redis Cluster報錯:Too many Cluster redirections


報錯信息

Spring Boot項目中訪問redis cluster報錯:
redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException: Too many Cluster redirections?(集群重定向過多)

原因分析

redis 綁定了多個ip
eg:

  1. redis.conf 文件中bind 127.0.0.1 192.168.186.1
  2. 在創建集群時host使用127.0.0.1 eg: redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1

問題修復

bind配置為主機ip(不要配置多個ip,也不要配置為回環地址127.0.0.1,配置為回環地址只有本機能訪問,其他主機無法訪問),重建集群 eg:redis-cli --cluster create 192.168.186.1:7000 192.168.186.1:7001 192.168.186.1:7002 192.168.186.1:7003 192.168.186.1:7004 192.168.186.1:7005 --cluster-replicas 1

  1. 所有節點redi.conf文件中bind配置為主機ip
  2. 刪除所有節點中的nodes.conf 、rdb文件
  3. kill所有redis進程
  4. 重新啟動所有redis實例
  5. 重建集群 redis-cli --cluster create 192.168.186.1:7000 192.168.186.1:7001 192.168.186.1:7002 192.168.186.1:7003 192.168.186.1:7004 192.168.186.1:7005 --cluster-replicas 1
  6. 重啟項目即可正常訪問

如果重建集群時報錯 :ERR] Node 192.168.186.1:7001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
可參考edis-cli --cluster create 創建redis集群報錯


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM