【问题标题】:Unable to connect redis server on AWS EC2 port 6379无法在 AWS EC2 端口 6379 上连接 redis 服务器
【发布时间】:2017-05-11 14:39:25
【问题描述】:

我在 EC2 上有两台服务器。一个托管我的 php 应用程序,另一个托管我的 redis 服务器。我在 redis 服务器上管理我的 php 会话和数据。因此,在我的 php 服务器上,我将 ip:port 作为会话保存路径并在 stderr 中发送了错误 FastCGI:“PHP 消息:PHP 致命错误:未捕获的异常 'RedisException' 和消息'连接关闭'

我需要在我的 redis 实例上为入站流量打开端口 6379。我通过在 AWS 安全组中设置自定义 TCP 设置来打开它,但端口仍然对外界关闭。但我能够监听 redis 服务器本身的端口。我在这个过程中遗漏了什么吗?我是否需要在某处进行任何其他更改。请指导我。我对 AWS 管理非常陌生 在实例 1 上:我正在使用 php、Apache 和 phpredis 在实例 2 上:使用 Redis

但是我在通过端口 11211 连接的实例 2 上安装了 Memcached,没有任何问题。我对 Redis 使用了相同的安全规则

【问题讨论】:

    标签: amazon-web-services networking amazon-ec2 redis amazon-vpc


    【解决方案1】:

    默认情况下redis只监听127.0.0.1,你需要明确告诉redis监听其他接口或任何节点。根据您的发行版,这可能类似于/etc/redis.conf

    最重要的是,如果你想让redis监听所有地址(0.0.0.0),你应该在redis.conf中设置proetected-mode no

    当您配置 redis 时,看在上帝的份上,请确保在您的安全组设置中,您定义端口仅对 IP 或安全组开放需要连接到redis的PHP服务器,而不是连接到整个世界。

    作为参考,这里是 redis.conf 中关于绑定的配置部分:

    # By default, if no "bind" configuration directive is specified, Redis listens
    # for connections from all the network interfaces available on the server.
    # It is possible to listen to just one or multiple selected interfaces using
    # the "bind" configuration directive, followed by one or more IP addresses.
    #
    # Examples:
    # 
    # bind 192.168.1.100 10.0.0.1
    # bind 127.0.0.1 ::1
    #
    # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
    # internet, binding to all the interfaces is dangerous and will expose the
    # instance to everybody on the internet. So by default we uncomment the
    # following bind directive, that will force Redis to listen only into
    # the IPv4 lookback interface address (this means Redis will be able to
    # accept connections only from clients running into the same computer it
    # is running).
    #
    # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
    # JUST COMMENT THE FOLLOWING LINE.
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    bind 127.0.0.1
    
    # Protected mode is a layer of security protection, in order to avoid that
    # Redis instances left open on the internet are accessed and exploited.
    #
    # When protected mode is on and if:
    #
    # 1) The server is not binding explicitly to a set of addresses using the
    #    "bind" directive.
    # 2) No password is configured.
    #
    # The server only accepts connections from clients connecting from the
    # IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
    # sockets.
    #
    # By default protected mode is enabled. You should disable it only if
    # you are sure you want clients from other hosts to connect to Redis
    # even if no authentication is configured, nor a specific set of interfaces
    # are explicitly listed using the "bind" directive.
    protected-mode yes
    

    【讨论】:

      猜你喜欢
      • 2017-09-04
      • 2012-12-26
      • 2020-09-30
      • 1970-01-01
      • 2020-06-29
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多