我有一个 Amazon AWS 账户。我想使用 ElastiCache Redis。我已经安装了 ElastiCache Redis。我如何从公共地址连接 ElastiCache Redis?
我已经安装了 Amazon Linux AMI。我正在从中访问 ElastiCache Redis。但我想从公共地址访问。
我有一个 Amazon AWS 账户。我想使用 ElastiCache Redis。我已经安装了 ElastiCache Redis。我如何从公共地址连接 ElastiCache Redis?
我已经安装了 Amazon Linux AMI。我正在从中访问 ElastiCache Redis。但我想从公共地址访问。
[更新] 正如下面卢克所提到的,这现在是可能的。下面是参考。 https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/accessing-elasticache.html#access-from-outside-aws
可悲的是没有。你可以参考这个问题。
您可以连接到亚马逊以外的 Amazon ElastiСache Redis 吗?
它提供了一个参考
http://aws.amazon.com/elasticache/faqs/#Can_I_access_Amazon_ElastiCache_from_outside_AWS
说明
永远不允许从 Internet 访问 VPC 内部或外部的 Amazon ElastiCache 集群。
如果您想从 Internet 或 VPC 外部的 EC2 实例访问部署在 VPC 内的 Amazon ElastiCache 节点,请参阅此处的指南。 http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Access.Outside.html
我目前用于开发目的的方法是
# main.go
package main
import (
"flag"
"fmt"
"io"
"net"
"sync"
)
var localAddr *string = flag.String("l", "localhost:9999", "local address")
var remoteAddr *string = flag.String("r", "localhost:80", "remote address")
func proxyConn(conn *net.TCPConn) {
rAddr, err := net.ResolveTCPAddr("tcp", *remoteAddr)
if err != nil {
panic(err)
}
rConn, err := net.DialTCP("tcp", nil, rAddr)
if err != nil {
panic(err)
}
defer rConn.Close()
var wg sync.WaitGroup
wg.Add(1)
go func() {
io.Copy(conn, rConn)
// conn2 has returned EOF or an error, so we need to shut down the
// other half of the duplex copy.
conn.Close()
wg.Done()
}()
wg.Add(1)
go func() {
io.Copy(rConn, conn)
rConn.Close()
wg.Done()
}()
wg.Wait()
}
func main() {
flag.Parse()
fmt.Printf("Listening: %v\nProxying: %v\n\n", *localAddr, *remoteAddr)
addr, err := net.ResolveTCPAddr("tcp", *localAddr)
if err != nil {
panic(err)
}
listener, err := net.ListenTCP("tcp", addr)
if err != nil {
panic(err)
}
for {
conn, err := listener.AcceptTCP()
if err != nil {
panic(err)
}
fmt.Println("handling connection")
go func() {
proxyConn(conn)
fmt.Println("connection closed")
}()
}
}
# run commands
go run main.go -l 0.0.0.0:9999 -r <redacted>.use1.cache.amazonaws.com:6379
Cloud9 实例可以替换为任何其他 EC2 实例。显然,添加所有这些跃点会产生性能成本。但它有效。
这有点模棱两可,但简短的回答是这通常是不可能的。根据定义,ECS 是私有的,因为它位于内存存储中并且需要极快的速度。允许从互联网访问不利于极快的速度。根据 AWS 文档 [1],您可能希望的唯一解决方法是通过 VPN 访问集群。
重要 将 ElastiCache 集群打开到 0.0.0.0/0 不会将集群暴露给 Internet,因为它没有公共 IP 地址,因此无法从 VPC 外部访问。但是,默认安全组可能会应用于客户账户中的其他 Amazon EC2 实例,并且这些实例可能具有公共 IP 地址。如果他们碰巧在默认端口上运行某些东西,那么该服务可能会无意中暴露。因此,我们建议创建一个将由 ElastiCache[2] 独占使用的 VPC 安全组。
-----参考资料----- [1] https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/accessing-elasticache.html#access-from-outside-aws [2] https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/accessing-elasticache.html#access-from-outside-aws