Redis连接问题 发布日期:2018-01-19 16:13:53     博主推荐★

最近有段时间没有写博客了,今天抽出时间写写,之前开发的时候redis部署在Linux是其他人搞得,我没怎么参与,于是闲着无聊在本地的虚拟机上安装了个redis进行测试,没想到在进行连接时报了下面这么一个错,fuck,Linux上的redis还真是麻烦,哪像windows上的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.
经过我英语0级的翻译,上面一共提供了四种解决方案,但是综合考虑为了简单起见只需要执行以下几步即可:

   
  1.修改redis.conf配置文件,将绑定的ip地址端口号给注释见下图 
  这里写图片描述

  2.由于Linux上的redis处于安全保护模式,这就让你无法从虚拟机外部去轻松建立连接,这里就有两种解决方法,一种是在redis.conf中设置保护模式为no,见下图 
  这里写图片描述

  3.另外一种方式是加上安全认证,即redis默认是没有密码的可以直接登录,这里加上密码,配置见下图 
  这里写图片描述

  4.好吧,此时你以为轻松解决问题了,于是再次在Linux启动redis服务器后,在外部连接还是报错,真是too young too native,起初我以为是配置没有生效,因为明明配置都写好了,于是杀掉redis的相关进程重启服务,结果发现还是没卵用。最后研究发现问题所在:之前启动redis-server并没有指定配置文件,而Linux上的redis比较操蛋的一点就是如果你不指定配置文件去启动,那么你做的修改就没有用,会读取默认配置(PS:至于这个默认配置在哪我也不清楚),于是用下面这种方式启动就可以使修改的配置文件生效,至于config rewrite命令我测试了并没有什么卵用。 
  这里写图片描述

  5.再次测试,在windows上进行jedis连接测试,出现下面pong(),恼人的错误终于消失了,比起windows版本的redis还真是让人龟毛啊,如果配置了密码认证,调用Jedis的auth方法输入密码即可 

文章转载于:http://blog.csdn.net/a532672728/article/details/78035559

博文地址:https://blog.ahamu.cn/blog/detail.html?id=254
   
推荐文章
  • 1
    sysbench
    2020/07/08
  • 2
    phper转java记录篇-spring boot
    2020/06/10
  • 3
    thinkphp5.0使用路由之后,post请求的
    2020/05/19
  • 4
    springboot单元测试aop失效
    2020/05/15
  • 5
    脑海中的JVM
    2020/05/12
  • 6
    IDEA搜索插件时显示search results
    2020/05/12
  • 7
    spring boot 配置加载源码查找
    2020/04/20
  • 8
    通过javap命令分析java汇编指令
    2020/04/16
  • 9
    IDEA小知识:查看JVM内存使用情况的步骤
    2020/04/16
  • 10
    springboot-加载自定义的properti
    2020/04/14
  • 11
    Jenkins执行shell脚本无法启动子进程解决
    2020/04/03
  • 12
    mac idea激活找专业的
    2020/04/02
  • 13
    Jenkins + DockerSwarm 实现弹
    2020/03/31
  • 14
    mac swarm学习过程
    2020/03/31
  • 15
    spring cloud
    2020/03/18
  • 16
    JAVA开发中遇到的问题记录002
    2020/03/12
  • 17
    JAVA开发中遇到的问题记录001
    2020/03/07
  • 18
    php -i查看信息
    2020/02/23
  • 19
    phpStorm中使用xdebug工具调试dock
    2019/12/09
  • 20
    讲的比较好的B+树执行原理的文章
    2019/12/09
最喜标签
NYOJ 面试 AJAX ping CentOS 灰度算法 YII2