【问题标题】:How Do I Connect to a Redis Sentinel that requirespass with ServiceStack.Redis?如何使用 ServiceStack.Redis 连接到需要通过的 Redis Sentinel?
【发布时间】:2017-02-16 03:50:03
【问题描述】:

我的本​​地机器上有一个简单的 redis 集群,包括:

  • 端口 3679 上的主机
  • 从端口 6380
  • 26379 端口上的哨兵

到目前为止,我正在使用 ServiceStack.Redis 进行连接,没有任何问题。今天我使用requirepass 42 设置为每个人添加了一个密码。我可以使用 Redis 桌面管理器很好地连接到所有这些,并且一切都按预期工作。

使用以下代码,我在尝试连接时收到错误消息。删除密码按预期工作。

var config = RedisConfiguration.Instance;

Func<string, string> hostFilter = host => string.IsNullOrEmpty(config.SecurityKey)
                                    ? $"{host}?db={config.Database}"
                                    : $"{config.SecurityKey}@{host}?db={config.Database}";


var sentinelHosts = config.SentinelHosts.Select(hostFilter);
var sentinel = new RedisSentinel(sentinelHosts, config.ServiceName)
{
    HostFilter = hostFilter,
    RedisManagerFactory = (master, slaves) => new RedisManagerPool(master)
};

sentinel.OnFailover += manager => Logger?.Warn($"Redis fail over to {sentinel.GetMaster()}");

sentinel.Start()

此代码抛出 RedisException "No Redis Sentinel were available",内部异常为 "unknown command 'AUTH'"

不清楚是我使用ServiceStack.Redis库不当还是我的Redis集群配置不正确。

有人能指出我正确的方向吗?

【问题讨论】:

    标签: redis servicestack.redis


    【解决方案1】:

    您可以使用HostFilter指定密码:

    sentinel.HostFilter = host => $"{config.SecurityKey}@{host}?db={config.Database}";
    

    但是当使用密码时,需要到处配置,即在Master and Slave configurations都使用:

    requirepass password
    masterauth password
    

    Redis Sentinel 还需要配置为使用相同的密码,以便它可以控制它所监视的 redis 实例,可以在您的 sentinel.conf 中配置:

    sentinel auth-pass mymaster pasword
    

    redis-config 项目中的 windows-password 文件夹显示了受密码保护的 Redis Sentinel 配置示例。

    【讨论】:

    • 这看起来可能是我的问题的根本原因。我会试一试,看看我能不能让它工作。
    • 好吧,你让我朝着正确的方向前进。最后,我必须将requirepassmasterauth 添加到我的主从配置中,然后将protected-mode 设置为no 我的哨兵。这似乎奏效了。 Here are my conf files 这有意义吗?
    • @NotMyself 从这里看起来不错。
    猜你喜欢
    • 2017-07-18
    • 2022-01-11
    • 1970-01-01
    • 2020-03-08
    • 2012-05-11
    • 2018-11-04
    • 1970-01-01
    • 2020-04-20
    • 2020-05-18
    相关资源
    最近更新 更多