。它是有可能连接到亚马逊弹性缓存从我的本地机器与java redis客户端(莴苣)?
我在安全组中定义了到TCP端口6379的入站规则和到任何IP地址的SSH端口22。
我的连接代码是:
RedisClient redisClient = new RedisClient("CacheCluster Endpoint", 6379);
RedisConnection<String, String> connection = redisClient.connect();
connection.set("key", "Hello, Redis!");
connection.close();
redisClient.shutdown();
我运行这个java得到:
Exception in thread "main" com.lambdaworks.redis.RedisConnectionException: Unable to connect to mycachecluster.b4ujee.0001.usw2.cache.amazonaws.com/172.31.34.211:6379
at com.lambdaworks.redis.AbstractRedisClient.initializeChannel(AbstractRedisClient.java:214)
at com.lambdaworks.redis.RedisClient.connectAsync(RedisClient.java:322)
at com.lambdaworks.redis.RedisClient.connectAsync(RedisClient.java:303)
at com.lambdaworks.redis.RedisClient.connect(RedisClient.java:259)
at com.lambdaworks.redis.RedisClient.connect(RedisClient.java:238)
at com.lambdaworks.redis.RedisClient.connect(RedisClient.java:222)
at project1.JavaRedis.main(JavaRedis.java:17)
Caused by: java.net.ConnectException: Connection timed out: no further information: mycachecluster.b4ujee.0001.usw2.cache.amazonaws.com/172.31.34.211:6379
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:574)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:224)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:289)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:619)
所以我的问题是:我做错了什么?我是否需要使用ClusterRedis EndPoint或EC2 DNS来建立连接?
请帮忙!!
谢谢! !
不能,你不能连接到它,因为它没有公共IP。DNS名称解析为一个私有IP 172.31.34.211,该IP只能在AWS VPC中访问。
此外,对于连接,您需要使用DNS,而不是IP,因为节点的IP可能会更改。如果你需要在本地使用Redis开发,你可以很容易地在本地机器上安装一个实例。
如果您仍然希望从本地连接到AWS ElastiCache (redis),而不将web服务托管在AWS上,则最好的方法是通过VPN。
我们使用https://pritunl.com,它很容易配置和使用。