【redis开启远程访问】关于DENIED Redis is running in protected mode because protected mode is enabled

redis开启远程访问

在Linux虚拟机上安装了redis后,启动redis,首先尝试本地访问连接
在这里插入图片描述

可以正常访问连接,尝试插入key-value,成功

接下来尝试远程连接,连接到我的虚拟机IP:192.168.182.120,提示以下错误:

Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: 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.
    at redis.clients.jedis.Protocol.processError(Protocol.java:127)
    at redis.clients.jedis.Protocol.process(Protocol.java:161)
    at redis.clients.jedis.Protocol.read(Protocol.java:215)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
    at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:196)
    at com.example.redis.JedisTest.main(JedisTest.java:24)

在这里插入图片描述

出现这个错误的原因很简单,redis默认只支持本地访问,不支持远程访问,要想远程访问IP,需要在配置文件中开启redis的远程访问即可,具体操作如下:

【解决方案】

1.输入命令:pstree -p,可树状展示进程并且展示进程号,找到redis-server的进程号
在这里插入图片描述

2.杀死当前的redis-server
在这里插入图片描述

3.再次查看运行的进程,已经没有redis的进程

4.修改redis目录下的redis.conf文件
在这里插入图片描述

5.找到如下图所示配置项
在这里插入图片描述

更改为

在这里插入图片描述

将redis服务设置为后台方式启动
在这里插入图片描述

保存更改的配置文件,退出

6.启动redis服务时加载修改后的配置文件重新以配置文件启动redis
在这里插入图片描述

7.远程模式访问redis,成功
在这里插入图片描述

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mayz梅子子子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值