使用ECS自己搭建Redis集群出现JedisCluster连接超时的问题

自己在阿里云的ECS(配置是1G ,1核)上搭建了一个redis集群(端口7000-7005),在服务器上测试

redis-cli -c -ip -p 7000

执行set,get方法的时候能够正确的重定向slot(定向到公网ip+端口,创建的时候是用公网ip创建的)
而且自己在电脑上的虚拟机上使用,和另外一台阿里云服务器

redis-cli -c -h 我的公网ip -p 7000

都能够正常访问,而且能够正确的重定向slot
但是我用Java的jedisCluster操作的时候就老是出现下面的问题

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

    at redis.clients.util.Pool.getResource(Pool.java:53)
    at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
    at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:66)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:116)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
    at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
    at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:31)
    at redis.clients.jedis.JedisCluster.set(JedisCluster.java:103)
    at JedisTest.test(JedisTest.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
    at redis.clients.jedis.Connection.connect(Connection.java:207)
    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
    at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
    at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
    at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
    at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
    at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
    at redis.clients.util.Pool.getResource(Pool.java:49)
    ... 38 more
Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at redis.clients.jedis.Connection.connect(Connection.java:184)
    ... 45 more

百度了好久,试了各种方法都不能解决问题,ESC的安全组配置也开放了7000-7005端口(0.0.0.0/0)和17000-17005(0.0.0.0/0)
redis.conf的配置文件

daemonize yes
appendonly yes
protected-mode no
cluster-enabled yes
cluster-node-timeout 15000
port 7000
cluster-config-file nodes-7000.conf

是不是因为阿里云服务器的问题导致的JedisCluster连接超时,想请各位大佬帮忙解决问题,停在这里好久了。
Java测试代码

        Set<HostAndPort> hostandports = new HashSet();
        hostandports.add(new HostAndPort("公网Ip",7000));
        hostandports.add(new HostAndPort("公网Ip",7001));
        hostandports.add(new HostAndPort("公网Ip",7002));
        JedisCluster jedisCluster = new JedisCluster(hostandports);
        System.out.println(jedisCluster.set("132455","aaaaaaaaaaaaa"));;
        System.out.println(jedisCluster.get("aaaaaa"));
当前问题共有如下(11)个解决方案
  • 1128938185934293
    1128938185934293

    我解决了 老铁 你解决没,没解决 可以发邮件 3130290751@qq.com 给我 ,我把我源码发你

  • 1603024127610837
    1603024127610837

    遇到同样的问题 ,无法解决

  • cowbin
  • 我姓徐
    我姓徐

    问题已经解决,直接修改cluster-nodes对应文件中的对应节点的IP,因为本楼主的nodes文件在对应的节点下是内网IP,直接修改成外网IP,并且同时要设置密码,就可以了

  • 夏周tony
    夏周tony

    首先是确认jedis的配置有没有问题,这个网上文章很多,可以确认下
    然后使用telnet测试下端口是否可达,排除网络问题

  • 我姓徐
    我姓徐

    我也遇见了同样的问题,好几台服务器,有的可以有的不可以,很奇怪

  • 1377272115415604
    1377272115415604

    你好,我也遇到了同样的问题,百度了好多都没能解决。。请问这个解决了没有

  • 一炮一群xpy
    一炮一群xpy

    巧了2333集群启动的时候用内网ip可以的创建成功.但是外网访问访问是可以通..但是要set他节点好像不能内部跳转。。。我用公网ip创建集群他就一直给我在哪里waiting for the cluster to join....... 老哥解决了嘛

  • 1630784119603826
    1630784119603826

    修改 Redis.conf 配置 cluster-config-file的指定文件,把私有ip更改为公网ip即可

  • 一家汪
    一家汪

    这个有没有解决啊,我也碰到了。。。。

  • cononyc
    cononyc

    备注下redis版本是3.2.9,jedis用的是2.9,然后ruby是2.3,gem中的redis是3.0.0(换成4.0一样的)

上一篇:putty无法连接ecs
下一篇:win2008+IIS7,ECS,总是打不开读写权限