Redis 3.2.0·以后·- Vagrant内的redis连接问题

本文详细解析了Redis 3.2.0之后版本中保护模式的开启原因及解决方法,包括如何修改bind地址和禁用保护模式,以及在不同场景下如何选择合适的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Redis-server 构建在Vagrant的Centos7上,
IP–192.168.44.10
参照: Redis.构建了Redis的Server
Centos7内测试,成功

确认

ps -ef | grep [r]edis              #redis程序存在确认
netstat -tln | grep 63*            #6309监听端口确认
systemctl status redis             #服务器运行状态确认
which redis-server                 #服务器安装场所确认

外部连接

.....................
nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.44.10:6379

原因

Redis默认只监听本机的连接
设定文件
/etc/redis.conf

By default, if no “bind” configuration directive is specified, Redis listens
for connections from all the network interfaces available on the server.
~~~ 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 loopback interface address (this means Redis will be able to
accept connections only from clients running into the same computer it
is running).

对应

屏蔽掉下面的一行

bind 127.0.0.1
更改为
bind 0.0.0.0
server重启

sudo systemctl restart redis

确认

再次连接确认,出现下面的信息

DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no
authentication password is requested to clients. In this mode connections are only accepted from the loopback
interface. If you want to connect from external computers to Redis you may adopt one of the following solutio
ns: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interf
ace by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly a
ccessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you c
an just disable the protected mode by editing the Redis configuration file, and setting the protected mode opt
ion to ‘no’, and then restarting the server. 3) If you started the server manually just for testing, restart i
t with the ‘–protected-mode no’ option. 4) Setup a bind address or an authentication password. NOTE: You only
need to do one of the above things in order for the server to start accepting connections from the outside.

原因

redis3.2.0 以后,bind IP地址未指定并且password未设定的情况下,默认开启了 protect-mode 模式。

解决

启动时指定 --protected-mode no
设定redis.conf文件内 --protected-mode no
设置密码(?)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值