【问题标题】:Amazon ElastiCache Redis Public AccessAmazon ElastiCache Redis 公共访问
【发布时间】:2014-08-13 23:58:27
【问题描述】:

我有一个 Amazon AWS 账户。我想使用 ElastiCache Redis。我已经安装了 ElastiCache Redis。我如何从公共地址连接 ElastiCache Redis?

我已经安装了 Amazon Linux AMI。我正在从中访问 ElastiCache Redis。但我想从公共地址访问。

【问题讨论】:

    标签: redis amazon amazon-elasticache


    【解决方案1】:

    [更新] 正如下面 Luke 所提到的,这现在是可能的。下面是参考。 https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/accessing-elasticache.html#access-from-outside-aws

    很遗憾,没有。你可以参考这个问题。

    Can you connect to Amazon ElastiСache Redis outside of Amazon?

    提供参考

    http://aws.amazon.com/elasticache/faqs/#Can_I_access_Amazon_ElastiCache_from_outside_AWS

    说明

    不允许从 Internet 访问 VPC 内部或外部的 Amazon ElastiCache 集群。

    【讨论】:

    【解决方案2】:

    如果您想从互联网或 VPC 外部的 EC2 实例访问部署在 VPC 内的 Amazon ElastiCache 节点,请参阅此处的指南。 http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Access.Outside.html

    【讨论】:

      【解决方案3】:

      我目前的开发方法是

      1. 在与我的 Elasticache 实例相同的 VPC 中创建一个 Cloud9 实例。
      2. 向 Elasticache 实例添加安全组规则,以允许来自 Cloud9 实例安全组的流量。
      3. 在 Cloud9 实例中运行一个微型 TCP 代理(用 Go 编写),代理进出 Elasticache 实例的流量。
      # 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
      
      1. 确保 Cloud9 实例的安全组允许公共访问代理正在运行的端口(例如 9999)。并从共享对话框中获取 Cloud9 实例公共 IP(例如 X.X.X.X)
      2. 从公共代理端点使用您的 Elasticache 实例(例如 X.X.X.X:9999)

      Cloud9 实例可以替换为任何其他 EC2 实例。显然,添加所有这些跃点会产生性能成本。但它有效。

      【讨论】:

        【解决方案4】:

        这有点模棱两可,但简短的回答是这通常是不可能的。根据定义,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

        【讨论】:

          猜你喜欢
          • 2018-04-29
          • 1970-01-01
          • 2021-08-19
          • 1970-01-01
          • 2021-09-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-02-02
          相关资源
          最近更新 更多