zoukankan      html  css  js  c++  java
  • 阿里云服务器搭建Redis集群踩到的坑(Redis Connection refused: no further information)

    一、问题:

      本人在阿里云上模拟了一个Redis集群(使用8001-8006),使用linux连接,所有都正常,但是使用Java客户端连接时(Java客户端与Redis集群不在同一服务器上),就出现了异常,说不能访问。

       集群安装:https://www.cnblogs.com/liconglong/p/14327430.html

    二、原因:

      排查过程就不说了,断断续续排查了半天,最后排查到原因:

      1、bind配置错误

      首先说一下bind的作用,其是用于限制哪些ip可以连接服务,redis.conf默认的bind值是127.0.0.1,即本机,因此导致Java客户端不能连接

      2、redis没有放开允许外部访问

      在redis.conf文件中有 protected-mode 参数,该参数表示是否允许外部访问,默认为no,就是不允许外部访问,这也是导致Java客户端不能访问的一个关键点

      3、集群创建

      创建集群时,使用的下面命令创建(使用了内网ip:127.0.0.1),导致创建时也默认的是本机访问

    ./bin/redis-cli --cluster create 127.0.0.1:8001 127.0.0.1:8002 127.0.0.1:8003 127.0.0.1:8004 127.0.0.1:8005 127.0.0.1:8006 --cluster-replicas 1

      4、阿里云安全组配置

      阿里云只开放了8001-8006这6个端口,没有开放18001-18006这6个端口

    三、解决:

      针对以上问题,逐一解决

        1、bind配置错误

      配置 bind 0.0.0.0 ,这样配置,说明可以允许所有ip访问

      2、redis没有放开允许外部访问

      在redis.conf文件中有 protected-mode 参数设置为 yes ,允许外部访问

      3、集群创建

      创建集群时,使用外部IP+端口(./bin/redis-cli --cluster create 8.131.245.111:8001 8.131.245.111:8002 8.131.245.111:8003 8.131.245.111:8004 8.131.245.111:8005 8.131.245.111:8006 --cluster-replicas 1)

    ./bin/redis-cli --cluster create 8.131.245.111:8001 8.131.245.111:8002 8.131.245.111:8003 8.131.245.111:8004 8.131.245.111:8005 8.131.245.111:8006 --cluster-replicas 1

    >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 8.131.245.111:8005 to 8.131.245.111:8001 Adding replica 8.131.245.111:8006 to 8.131.245.111:8002 Adding replica 8.131.245.111:8004 to 8.131.245.111:8003 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master M: c8d8397a94e420fcd34d6f3cdec09c0df7858829 8.131.245.111:8001 slots:[0-5460] (5461 slots) master M: 6c8cb2e6ed25da78d52c6c56afac4912f5c2f2fe 8.131.245.111:8002 slots:[5461-10922] (5462 slots) master M: 3549ac50dc141dbd0a697e72cd1ab3ea02360976 8.131.245.111:8003 slots:[10923-16383] (5461 slots) master S: 0c2c0b4db9610c1343980de1763199e0e69ab0aa 8.131.245.111:8004 replicates c8d8397a94e420fcd34d6f3cdec09c0df7858829 S: 6a73b5f7fe830607e0c6e4744b437a1ff3626b43 8.131.245.111:8005 replicates 6c8cb2e6ed25da78d52c6c56afac4912f5c2f2fe S: 602009707eb9aa1867450d1da7ae7a67548aeedc 8.131.245.111:8006 replicates 3549ac50dc141dbd0a697e72cd1ab3ea02360976 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join ...... >>> Performing Cluster Check (using node 8.131.245.111:8001) M: c8d8397a94e420fcd34d6f3cdec09c0df7858829 8.131.245.111:8001 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 0c2c0b4db9610c1343980de1763199e0e69ab0aa 8.131.245.111:8004 slots: (0 slots) slave replicates c8d8397a94e420fcd34d6f3cdec09c0df7858829 S: 6a73b5f7fe830607e0c6e4744b437a1ff3626b43 8.131.245.111:8005 slots: (0 slots) slave replicates 6c8cb2e6ed25da78d52c6c56afac4912f5c2f2fe S: 602009707eb9aa1867450d1da7ae7a67548aeedc 8.131.245.111:8006 slots: (0 slots) slave replicates 3549ac50dc141dbd0a697e72cd1ab3ea02360976 M: 3549ac50dc141dbd0a697e72cd1ab3ea02360976 8.131.245.111:8003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) M: 6c8cb2e6ed25da78d52c6c56afac4912f5c2f2fe 8.131.245.111:8002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.

      4、阿里云安全组配置

      开放集群的所有端口(8001-8006),以及集群端口+10000的端口(18001-18006),这里我为了以后方便,索性直接将1-19999端口全部开放了

    四、验证

      重新连接客户端,大功告成

      说明:如果之前是按照错误方式创建过集群,那么需要先将之前的AOF(appendonly.aof)、RDB(dump.rdb)和集群部署文件(nodes.conf)

    ------------------------------------------------------------------
    -----------------------------------------------------------
    ---------------------------------------------
    朦胧的夜 留笔~~
  • 相关阅读:
    HDU 4801 Pocket Cube
    HDU 5008 Boring String Problem(后缀数组+二分)
    2-Sat问题
    后缀数组
    树形DP
    图论
    SRM 628 DIV2
    组合博弈
    Github使用笔记
    VS2010+OpenCV配置
  • 原文地址:https://www.cnblogs.com/liconglong/p/14358096.html
Copyright © 2011-2022 走看看