当我按照此处的部署指南尝试连接到主节点时,我面临MasterNotFoundError:https://docs.bitnami.com/tutorials/deploy-redis-sentinel-production-cluster/
我连接到Redis Sentinel主节点的代码是:
from redis.sentinel import Sentinel
redis_host = 'redis.default.svc.cluster.local'
redis_port = 26379
sentinel = Sentinel([(redis_host, redis_port)], socket_timeout=0.1, password='abc')
redis_client = sentinel.master_for('mymaster', password='abc')
在他们的GitHub repo中,我看到sendinel.masterSet的配置默认设置为mymaster。但是,当我尝试使用以下代码递增时:
redis_client.incr('counter', 1)
我遇到redis.sentinel.MasterNotFoundError:找不到'mymaster'错误的主服务器。
我该如何解决?谢谢。
您在哪里执行该代码?如果尝试从群集外部连接,则需要将服务设置为LoadBalancerIP。在执行代码之前,您是否测试过是否直接连接到该主机?使用ping
。在这里,您可以看到如何将哨兵服务部署为LoadBalancer:https://github.com/bitnami/charts/tree/master/bitnami/redis。您需要将sentinel.service.type
设置为LoadBalancerIP
。希望对您有帮助。