gpt4 book ai didi

amazon-web-services - 无法连接 AWS EC2 端口 6379 上的 Redis 服务器

转载 作者:IT王子 更新时间:2023-10-29 06:08:20 27 4
gpt4 key购买 nike

我在 EC2 上有两台服务器。一个托管我的 php 应用程序,另一个托管我的 redis 服务器。我正在管理我的 php session 和 redis 服务器上的数据。因此,在我的 php 服务器上,我将 ip:port 作为 session 保存路径,并在 stderr 中收到错误 FastCGI:“PHP 消息:PHP fatal error :未捕获的异常‘RedisException’,消息为‘Connection closed’

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

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

最佳答案

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

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

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

作为引用,这里是 redis.conf 中关于绑定(bind)的配置部分:

# 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

关于amazon-web-services - 无法连接 AWS EC2 端口 6379 上的 Redis 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41342972/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com