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

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
设置密码(?)

猜你喜欢

转载自blog.csdn.net/oblily/article/details/87918737