当前位置: 代码迷 >> 综合 >> Linux系统安装redis后spring访问不到,保护模式‘CONFIG SET protected-mode no‘ 已解决
  详细解决方案

Linux系统安装redis后spring访问不到,保护模式‘CONFIG SET protected-mode no‘ 已解决

热度:63   发布时间:2024-02-26 21:53:31.0

先粘一下错误信息

org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: 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.

先大致看一下这几句话的意思:

被拒绝,Redis运行在保护模式下,因为保护模式是启用的,没有指定绑定地址,没有认证密码要求客户。在这种模式下,连接只接受环回接口。如果你想从外部电脑连接到Redis,你可以采用以下其中一种解决方案

然后他给出了四种解决方案

通用命令先列出来:

重启
进入redis安装的src目录后输入停止和启动命令

redis-cli shutdown
redis-server ../redis.conf

查看redis是否已启动

ps -ef | grep redis

在这里插入图片描述
有第二个说明启动好了

解决方案:

1.只是禁用保护模式发送命令’CONFIG SET保护模式no’从环回接口连接到Redis从同一主机服务器运行,但要确保Redis不是公开从互联网上访问,如果你这样做。使用配置重写使此更改永久.

具体操作就是去更改redis的配置文件redis.conf第69行
在这里插入图片描述

2.可以通过编辑Redis配置文件来禁用保护模式,并将保护模式选项设置为“no”,然后重新启动服务器

redis.conf第88行

在这里插入图片描述

3.如果只是为了测试而手动启动服务器,请使用“–protected-mode no”选项重新启动它

临时有效,启动的时候在后面加参数就好了--protected-mode no别忘了空格哦

4.设置绑定地址或身份验证密码

第500行在这里插入图片描述
可以在下面另起一行写你的redis密码,当然在项目中也要加配置作为访问密码

最后温馨提示NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
注意:为了让服务器开始接受来自外部的连接,您只需要执行上述操作之一

  相关解决方案