【问题标题】:Connect refused for jedis with redis cluster使用 redis 集群连接拒绝 jedis
【发布时间】:2017-12-27 03:09:15
【问题描述】:

我正在尝试使用 jedis(在连接到同一网络的本地计算机上)连接到我的 redis 集群(在远程服务器上)。

我的redis集群是由以下ip组成的:

10.x.x.x:6380

10.x.x.x:6382

10.x.x.x:6385

我的 redis 实例 10.x.x.x:6380 的配置文件是:

port 6380
cluster-enabled yes
cluster-config-file nodes-6380.conf
cluster-node-timeout 5000
appendonly yes
protected-mode yes
#daemonize yes
bind 127.0.0.1 10.x.x.x(machine ip)

但问题是,当我尝试运行我的 redis 服务器实例时,出现以下异常:

[admin@dn2 6380]$ redis-server  redis.conf 
10965:M 21 Jul 02:58:04.100 # Creating Server TCP listening socket (local machine ip):6380: bind: Cannot assign requested address

谁能告诉我我在这里做错了什么???提前致谢。

我的绝地计划是:

        Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        //Jedis Cluster will attempt to discover cluster nodes automatically
        jedisClusterNodes.add(new HostAndPort("10.x.x.x", 6380));
        jedisClusterNodes.add(new HostAndPort("10.x.x.x", 6382));
        jedisClusterNodes.add(new HostAndPort("10.x.x.x", 6385));
        JedisCluster jc = new JedisCluster(jedisClusterNodes);
        jc.set("foo", "bar");
        String value;
        System.out.println(value = jc.get("foo"));

【问题讨论】:

    标签: jedis redis-cluster


    【解决方案1】:

    哎呀。从我的角度来看,这是一个愚蠢的错误。

    从 redis.conf 中的bind 标记中删除机器 ip 和 127.0.0.1 并指定正确的主机 ip(即,在我的情况下为 10.x.x.x)。

    同样把protected-modeno放到redis.conf中

    此外,当使用./redis-trib.rb 创建集群时,主机 ips 应该以正确的格式(10.xxx)提及,而不是放置 localhost(即,不是 127.0.0.1),即使所有 redis 实例都在同一台服务器上运行。

    【讨论】:

      猜你喜欢
      • 2015-10-13
      • 2021-10-22
      • 1970-01-01
      • 2018-12-04
      • 2016-12-10
      • 2020-07-24
      • 2019-04-04
      • 2018-05-15
      • 2016-09-28
      相关资源
      最近更新 更多