org.springframework.data.redis.RedisConnectionFailureException,java操作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 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

这个错误发生在springboot2.0整合redis实现消息订阅功能时,因代码无法连接到redis服务器产生的错误,上述内容说是提供4种方法任意执行一种即可。
综合网上查询的解决办法,提供一下设置,变更完毕即可,因博主是linux环境,只说明linux操作。


  • 找到redis安装目录,开始编辑redis.conf文件,windows版的好像是redis.windows.conf
  • 接着使用 vi命令开始编辑配置文件,需要修改的地方已经标出

    1、给bind 127.0.0.1添加注释,若需要指定若干ip访问,则直接改成指定ip访问,不然开启就是本机访问;
    2、将protected mode yes 改成protected mode no,意思是是否启用保护模式;

    操作命令如下:

1. vi redis.conf;
2. 找到待修改内容,光标移动上去,按a键,开始进行操作编辑;
3. 将上述内容都找到并修改完成后,按ESC键,之后输入:wq进行保存;
  • 启动redis
    这里有一个坑需要说明一下,启动redis的时候是要携带刚刚修改的配置文件的,如果不携带则还是使用的默认配置。(博主被这个地方坑了2个小时,真的傻了)
    还去弄了防火墙、端口开放等等,服务器都重启了几遍还没生效,原来最后才发现,启动没有带配置文件。。。

另外,操作这些的时候,尽量用root,不然可能会没有权限的su root

你可能感兴趣的:(redis)