远程连接redis问题

自己一直都是连本地redis,直接上localhost,没毛病。心血来潮连个linux系统上的redis,就遇到了连接不了的问题

问题1

使用IDEA搭建SpringBoot将redis服务器ip地址改为另一台电脑时,出现错误,项目无法启动,但是ping目标地址能ping通,通过本地电脑的redis进行连接

redis-cli -h 192.168.xx.xxx -p 6379
结果:由于目标计算机积极拒绝,无法连接

之前以为是防火墙的问题,就进行了下述操作,但并没有用,不知道该操作影响到后面没有就贴了上来

// 查询端口是否开放
firewall-cmd --query-port=6379/tcp
// 开放端口
firewall-cmd --permanent --add-port=6379/tcp
// 重启防火墙
firewall-cmd --reload

解决1

百度看到这篇帖子redis由于目标计算机积极拒绝,无法连接,了解到只要更改redis的配置文件redis.conf就可以解决这个问题,但是因为自己通过apt-get安装的redis,不清楚这些文件放哪了通过whereis redis.conf找到了对应的文件目录
远程连接redis问题_第1张图片
在对应目录使用sudo vim redis.conf命令打开该文件将bind127.0.0.1注释掉,
远程连接redis问题_第2张图片
通过redis-server /etc/redis/redis.conf重启redis,尝试连接,但发现并没有用,还是拒绝连接,果断重启装linux的那台电脑,果然解决了这个问题,在本地电脑使用redis-cli连接也成功了,但是输入命令无效,产生了下一个问题

问题2及解决

可以连接但是命令不起作用,SpringBoot报错

Caused by: io.lettuce.core.RedisConnectionException: 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 solutions:
 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.
 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server.
 3) If you started the server manually just for testing, restart it 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.

通过提示将配置文件的protected-mode这个参数设为no就成功解决了,当然也是重启了redis以及电脑。
远程连接redis问题_第3张图片

你可能感兴趣的:(Java,linux,redis,java)